Android Programming Tutorials

(Romina) #1
Getting More Active

</application>
</manifest>

Notice the second element, referencing the DetailForm class.


Also note that it does not need an , since we will be


launching it ourselves rather than expecting the system to launch it for us.


Then, we need to start this activity when the list item is clicked. That is


handled by our onListClick listener object. So, replace our current


implementation with the following:


private AdapterView.OnItemClickListener onListClick=new
AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position,
long id) {
Intent i=new Intent(LunchList.this, DetailForm.class);

startActivity(i);
}
};

Here we create an Intent that points to our DetailForm and call


startActivity() on that Intent. You will need to add an import for


android.content.Intent to LunchList.


At this point, you should be able to recompile and reinstall the application.


If you run it and click on an item in the list, it will open up the empty


DetailForm. From there, you can click the BACK button to return to the


main LunchList activity.


Step #3: Move the Detail Form UI......................................................


Now, the shredding begins – we need to start moving our detail form


smarts out of LunchList and its layout to DetailForm.


First, create a LunchList/res/layout/detail_form.xml, using the detail form


from LunchList/res/layout/main.xml as a basis:


111
Free download pdf