Sunday, June 27, 2010

Pedestal Sinks Towel Bar Ontario

Create a daughter Activity (with code) Create a

In the previous post Create an Activity daughter I posted the explanation in the form of two wave that Google had used during the study. But I noticed that the requirements are very stringent browsing, so that is not visible on mobile devices. Better then repeat the post in normal form.


ANDROID: CREATION OF A DAUGHTER ACTIVITY

Purpose: I have a demo application based on ListView and SimpleAdapter and I have to enter a dialog modal that allows me to insert new data into the ListView.

Study and Documentation:
  • How to integrate the new class in the Activity
  • Recalling the time button to the Activity chosen
  • Two options for handling data
    • Inserting data into the database made by Activity secondary and primary updates the data entry View
    • Activity in primary care receiving crude from the secondary (best)

RECALLING THE ACTIVITY

1) It is declared as private member of a handler in the Activity primary ADD button, the value of the initialized at OnCreate.

private Button mAddAccountButton;



public void onCreate (Bundle savedInstanceState)
{
...
mAddAccountButton = (Button) findViewById ( R.id . AddContactButton)



2) There is an OnClick Listener which launches a special member function of private primary Activity.

mAddAccountButton.setOnClickListener (new View.OnClickListener () {

public void onClick (View v) {
launchContactAdder ();

}});


3) The member function to launch the secondary creates a new Activity Intent with reference to the same sub-class of the Activity. Then start this Activity.

protected void launchContactAdder () {

Intent i = new Intent (this, ContactAdder.class)
startActivity (i);
}

how to integrate the class in

1) Create a standard layout to be invoked after the Class Activity


http://schemas.android.com/apk/res/android "
android: orientation =" vertical "
android: layout_width = "fill_parent"
android: layout_height = "fill_parent">



android: text = "PROVAAAAAA"
android: layout_width = " wrap_content "
android: layout_height =" wrap_content " />

android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "A" />

android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: text = "DUE" />




2) Create a new file with JAVA in the general declaration of an activity.

TaskAdder extends Activity {public class

/ / private ArrayList > data;
/ private / adapter SimpleAdapter;

/ ** Called When the activity is first created. * /
@ Override public void
onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState)
setContentView (R.layout.taskadder);}

}

3) it must be held inside the MANIFEST the new Activity, just below the main application.


android: label = "@ string / app_name">


DATA MANAGEMENT

He said there were two options, to manage data storage at the primary or secondary activity .

Seeing some examples, such as Notepad to Google, it seems that the trend is to manage all the secondary activity, so that when you return to the primary is all perfectly consistent. It may make sense, so you avoid double validation data, and the fragmentation of operations on data in two different activity (less interdependence).

In any case, deserves to be printed using the example ContactManager http://www.anddev.org


ANDROID: MOVE DATA BETWEEN ACTIVITY

The next step that has created a secondary activity is to pass data back and forth between the same Activity.

Overview: Google http://developer.android.com/guide/appendix/faq/framework.html FAQ # 3

There are three classes of data:
  • Primitives: directly using the method putExtra intent
  • not persistent use application public static, singleton, hashmap of weakreferences
  • Persistent: using preferences, files, SQLiteDB, ContentProvider

For the first version of the test application will use public static with non-persistent data, which allows me to make the least changes possible. Virtually call the public static variable calling it up and then use it externally nomeclasse.nomevar .

Here we are implementing.

As mentioned earlier the ideal is to make the databases, making them visible to every public static Activity.


Domo extends Activity {public class
public static ArrayList > data;
SimpleAdapter public static adapter;
...

After that Activity in the secondary is slightly modifies the code already tested in the primary by collecting the data to be entered from the graphical interface of the sub-Activity, where the user has paid to type.


/ / handle the click on the button ONE
View.OnClickListener mOneListener OnClickListener = new () {
public void onClick (View v) {
ET1 = alt text (alt text) findViewById ( R.id . editname)
et1.getText String st1 = (). toString ();
ET2 = edit text (alt text) findViewById ( R.id . edit date);
et2.getText String st2 = (). toString ();
HashMap taskMap = new HashMap ( )
taskMap.put (t_imgres "R.drawable.task_2)
taskMap.put (t_name ", st1);
taskMap.put (t_date", st2);
Domo.data.add (taskMap) / / put the hashmap listings
Domo.adapter.notifyDataSetChanged ();}

};


Button btnOne;
btnOne = (Button) findViewById ( R.id . btnTaOne)
btnOne.setOnClickListener (mOneListener);

0 comments:

Post a Comment