Android :: Extracting Activity Code And Creating Graph View Class

Mar 1, 2010

I had a bunch of code in an activity that displays a running graph of some external data. As the activity code was getting kind of cluttered, I decided to extract this code and create a GraphView class:

public class GraphView extends LinearLayout {
public GraphView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.graph_view, this, true);
}
public void start() {
// Perform initialization (bindings, timers, etc) here
}
public void stop() {
// Unbind, destroy timers, } }

Moving stuff into this new LinearLayout-derived class was simple. But there was some lifecycle management code associated with creating and destroying timers and event listeners used by this graph (I didn't want this thing polling in the background if the activity was paused, for example). Coming from a MS Windows background, I kind of expected to find overridable onCreate() and onDestroy() methods or something similar, but I haven't found anything of the sort in LinearLayout (or any of its inherited members). Having to leave all of this initialization code in the Activity, and then having to pass it into the view seemed like it defeated the original purpose of encapsulating all of this code into a reusable view. I ended up adding two additional public methods to my view: start() and stop(). I make these calls from the activity's onResume() and onPause() methods respectively. This seems to work, but it feels like I'm using duct tape here. Does anyone know how this is typically done?

Android :: Extracting Activity Code and Creating Graph View class


Android :: How Do You Get View Reference From Class That DOES NOT Extend Activity?

Jul 20, 2010

I want to have a class "Utils", that will have several methods used all over my code. For example, I have a top bar with a textview and two ImageButtons that must display different texts and icons on different activities.I created the class Util, but it doesn't extend Activity. The problem is that if it doesn't, findViewById isn't there, can't find stuff etc.

View 1 Replies View Related

Android :: Creating A New Class Using Eclipse New Java Class Dialog Box

Jul 7, 2010

I'm creating a new class, using eclipse "New Java Class" dialog box. I can write the superclass I want (I can't find using "browse" button), but I can't write or select an interface to implement. I click "add" but ther is nothing to select. What I'm doing wrong?

View 4 Replies View Related

Android :: Call Method In Main Activity From Custom View Class

Aug 8, 2010

I am using the following method in a new application I'm developing. There is a main activity, which instantiates different classes that extends RelativeLayout and I'm using setContentView to switch between the different modules of the application. I wonder if this is a good approach or necessarily I have to use different activities to the several screens the app haves.

View 1 Replies View Related

Android :: Communicating Between Receiver Class And An Activity Class

Jul 14, 2010

I'm just getting into Android development, and I have a question about communicating between a receiver class and an activity class. I'm very new to JAVA and Android so I hope I don't sound too stupid. I'm developing an application where I intercept an SMS message and then based on various elements of that SMS I might delete it once it's been saved to the inbox. I have a receiver class that intercepts the txt message, and I am also able to delete messages from my inbox with code in the activity class using a button at the moment. The problem I have is communicating between the receiver class and the activity class where the code to delete a message resides. I tried putting that code directly into the receiver class but as I'm sure most of you already know the BroadcastReceiver class doesn't seem to support what I need to delete messages. I've been searching for an answer to this for a while, but haven't been able to find anything. Honestly I'm not sure I know enough about JAVA and Android to even recognize a solution if I saw it.

View 2 Replies View Related

Android :: Access Application Class From Class Other Then Activity

Sep 8, 2010

I'm new to Java and android development. In my application I need data which is accessible for a few activities. I've read that a good solution is to use Application class for this. So I use it like this:

public class MyApplication extends Application {
private String str;
public String getStr(){
return str;
}
public void setStr(String s){
str = s;
}
}

and I can access this variable from activity like this:........................................

View 2 Replies View Related

Android :: Call Activity Class From Other Java Class?

Oct 8, 2010

I have just started android. I just want to know that how can i call activity class from other java class. i just want to pass class object to activity class.

public class GsonParser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MagazineThread thread=new MagazineThread();
thread.start();
}
public GsonParser(JsonMagazineParser Obj)
{

}
}

and i am just doing like from other class. GsonParser obj=new GsonParser(this);passing obj to activity class.how can i achieve that.

View 1 Replies View Related

Android :: Dialog Class With It's View Class?

May 19, 2009

I made a Dialog Class with it's view classI want to pop up the dialog when I got some packets from network. so I made a Thread which parses packets and then I made if clause in Run() method There is no problem with parsing packet but when I enter "if clause" and call showDialog() I got Error message

Is there anyone who knows how to pop up a dialog from different thread?

View 2 Replies View Related

Android :: Custom View Extending View-Class / Still Based On XML-Layout

Aug 17, 2010

I want to build my own custom view which should look like the Crysis-GUI.At first I designed a XML-based Layout and made it visible via the setContentView(int resid)-Method. Worked pretty well.But now I wan't to go a step further and draw in my Layout. So I created a new Class, let it extend View and overrode the onDraw()-Method. So far so good.But how can I still use my XML-Layout? I can't do setContentView anymore, so how could the same effect be achieved?

View 1 Replies View Related

Android :: Creating Different Builds For Same Source Code

Feb 25, 2010

I have a Android project for SDK1.5 and now I want to convert it for SDK2.1 with some constant changes for the UI. Should I create a complete new Project or the existing project can be manipulated for including the lastest changes. I'm using Eclipse for Development.

View 1 Replies View Related

Android :: Start An Activity From Non Activity Class

Aug 19, 2009

An activity can be called from existing activity through *startActivity(intent); *

Is t possible to call an activity from non Activity class ? and how?

View 2 Replies View Related

Android :: Creating A WebView In The Top Of A View

Aug 2, 2010

I'm trying to do a fairly simple thing but i'm failing since 3 hours.

I have a WebView that i show with some pictures and html stored in local sdcard. After the user clicks a button in my app, i want to show the webview, and when he press the back button, i want to return to the previous view (which is my main app view).

How to do it? I tried this:

CODE:.............

However, when i press back, my app quits.

View 5 Replies View Related

Android :: How To Get Package / Class Name By Code?

Nov 15, 2009

How can I use sdk to get the package/class name of a specific apk file, eg: I have a test.apk, and I want to know the package name and class name by API when I write a android program.

View 2 Replies View Related

Android :: Creating Diamond Shape View Using 2D Or 3D

Nov 22, 2010

how can we create diamond shape view using 2D or 3D,I need to show the Images in that customized view instead of default ImageView class

View 2 Replies View Related

Android :: Creating View With Particular Style Programmatically

Jun 1, 2010

Other questions say that the style cannot be set programmatically, but a View can be initialised with a style such as when it is loaded from XML.How can I initialise a View with a particular style programmaticly (not in XML)? I tried using View(Context context, AttributeSet attrs, int defStyle), but I don't know what to parse in for the second argument. Passing in null results in the View not being displayed

View 1 Replies View Related

Android :: Code To Serialize Manually A Class?

Sep 2, 2010

I want to serialize my class. I have this code...

I apparently need to implement :

private void writeObject(java.io.ObjectOutputStream out) throws IOException

private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException

Anyone know what I should do in these function ?? How should I write my Bitmap variable ?Any code examples ? anyone did it ?

View 2 Replies View Related

Android : Construct Class Diagram From Code?

Oct 19, 2010

I have a huge codebase. I am not very clear about its design as documents are rear to find.

Is there any tool available to construct the class diagram from the code? I need to know the interactions between the classes and relations between them. If there is any such tool where i can give the entire code as input and get the class diagram as out put, it will be best for my understanding.

View 2 Replies View Related

Android :: Code Won't Work In New Class / Resolve This?

Aug 31, 2010

The code in the main class works perfekt but i need a other thread but there the code won't work code...

The method create(Context, int) in the type MediaPlayer is not applicable for the arguments (Alarm, int)

and

The method getSystemService(String) is undefined for the type Alarm

View 1 Replies View Related

Android : Put All Code Relating To Creating Time - Date Dialogs Setting Values

Sep 24, 2010

I'm currently learning android and java, and I am having some issues with importing a java file.

I am working with the time and date example in the android api demos, and I want to put all the code relating to creating the time and date dialogs setting the values etc into a separate java file, and in my main java file run when the application starts, just declare the buttons and onclick events.

What is the best way to do this? Do I need to put all the code inside a class(that extends activity) or method? How do I use this inside my main class. Code...

View 1 Replies View Related

Android :: Can I Start Activity Without Creating A New One?

Jul 31, 2010

In a broadcast receiver I want to do the following:
1. See if MyActivity is alive somewhere. 2. If it is, bring it to the foreground. 3. Otherwise, start a new MyActivity.

View 3 Replies View Related

Code For Creating Roulette Wheel Circle?

Dec 7, 2011

I'm trying to create an app which starts off using a spinning wheel from which the user spins and selects an option (similar to a roulette wheel).

where there may be hints to creating the code.

View 1 Replies View Related

Android :: Creating Own View Type From Layout File?

Mar 9, 2010

not sure how to inflate this from my layout file: MyView v = LayoutInflater.from(this).inflate(R.layout.myview, null); the inflater of course does not know what 'MyView' type is, and returns only View. What's a good way to reconcile this?

View 1 Replies View Related

Android :: Creating Multiple Objects Of View Defined In Xml

Jun 9, 2010

I have to dynamically add a list of views (the views use RelativeLayout). Can I do this by specifying the view definition in xml and instantiate multiple objects off it? This gives the usual benefits of separating the view part from the code (for e.g., making it easy for the UI guys to alter things) or Is going the ArrayAdapter the suggested/only route?

View 1 Replies View Related

Android :: Creating And Showing A View/window From A Service

May 22, 2009

I want to show a view on calling a Service API. Currently the only way looks like using the Toast class.

I tried the following after getting the WindowManager service, but it crashes at addView. I looked into the Toast class and found that it uses WindowManagerImpl which is not accessible publicly - is there any way to access the WindowManagerImpl functionality?

CODE:.................

View 4 Replies View Related

Creating Android Calendar - Month / Week / Day View

Sep 4, 2012

Can I have some tutorial to create simple android calendar? How to show month view, week view, day view, and create activity.

View 1 Replies View Related

Android :: Want To Look At Source Code For ListAdapter Class Without Downloading

Nov 22, 2010

I want to look at the source code for the ListAdapter class without downloading the entire Android source code tree. Is there a way to do that?

View 4 Replies View Related

Android :: SetContentView Fails / When Creating New Activity

Jan 19, 2010

My code is calling setContentView(R.layout.someLayoutID); from an activities' onCreate method. The activity is launched with the following: Code...

View 4 Replies View Related

Android :: Can't Get Layout Info / When Creating Activity

Jul 22, 2010

I have this element in my layout XML:
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_width="320sp" android:layout_height="380sp"
android:layout_gravity="center" android:background="#99CC33">
</FrameLayout>
And I want to get its position on the screen with getTop(), getBottom() but I want to do it only once.
I was trying to do it on the onCreate(), but those methods return all 0 as response.

View 1 Replies View Related

Android :: Source Code (or Git File) For ContactsContract.QuickContact Class?

Jul 15, 2010

What is the .git file corresponding to ContactsContract.QuickContact class?

View 2 Replies View Related

Android :: Creating A Stub Of An Activity In Testing Project

Jul 22, 2010

I want to create a stub of one of my Activities, but I want to keep it in the test project so not to have it in the actual apk. I don't seem to be able to find a way to do it though. I get this:

java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.example.test.StubActivity }

I did find if I put it in the main project and put it in the manifest accordingly (IntentFilter:(Action:Main, Category:Default)) it will work, well it actually crashed, but I am not bothered by that. Something to fix later on.I did think about putting everything in the same main project and just have a test package, but that would then involve messing the manifest, I think. It seems better to keep them separate. It's just cleaner.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved