Posts Tagged ‘View’

Android: loading images from a remote sever, SD card and from the Resources folder

Click here to read Android: loading images from a remote sever, SD card and from the Resources folder

As stated on the title, this post will explain how to load a image from 3 different sources: the SD card, from a remote server and from the Resources folder. Since the methods and code used to load these images from these sources are different from one another, this post is going to be divided into three different parts, one for each location.

Select one of the following links to go to a specific part of the post: (more…)

Android: touchscreen ‘swipe’ movement detection

Click here to read Android: touchscreen ‘swipe’ movement detection

This post explains how to code a simple swipe screen movement detection that can be used to control characters and other objects on an Android game or any other application.

All this code is written inside the View class, so open it up and let’s get to it. The first thing we will have to do is to create four different variables: one pair will store where the screen was touched, and the other one will be used to store the difference between the location where the screen has been pressed and where the screen has been released. Create this variables and assign zero to all of then, like this: (more…)

Access Activity class from View

Click here to read Access Activity class from View

So, it begins! This is the first on this blog!

Let’s start with a Android Programming tip: how to access the Activity from an instantiated View object.

The first thing to do is consider if you really need to call an Activity from a View. Take some time to analyze your classes and their relationships. Probably, the variable/method you need to access doesn’t have to be a member of the Activity class. In that case, think about placing that variable/method inside the View or create a new class that has variables/methods which can be accessed by both Activity and View. Unless an Activity variable or method (e.g. Activity.finish() ) needs to be called from the View, there is no need to try to access the Activity from the current View.

But if you need to access a method/variable of the calling Activity from the View, here is how it’s done:

(more…)

Page 4 of 41234