Android Tutorial(4)Detail Page Introduction
Android Tutorial(4)Detail Page Introduction
Some Tips:
1. How to browse the database sqlite on Android.
Solution:
Download the software for MAC from here http://sourceforge.net/projects/sqlitebrowser/?source=dlp
The name of the file is sqlitebrowser_200_b1_osx.zip.
And directly open the data file from Android. From eclipse, choose the DDMS and then go to File Explorer
/data/data/com.sillycat.packagename/databases/DataBaseName
That is nice.
How to Add Detail Link to my List Pages.
There are 2 ways to do that.
1. Add Click Listener to the Item
In the refresh state of the List page.
publicvoid refreshStates(final List<ILPLocation> items) {
if (items == null || items.isEmpty()) {
return;
}
LocationsListAdapter adapter = new LocationsListAdapter(this, items);
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new ListView.OnItemClickListener(){
publicvoid onItemClick(AdapterView<?> parent, View view, int position,long id) {
ILPLocation item = items.get(position);
Log.d(TAG, "You are hitting item Name= " + item.getName() + " id = " + item.getID().getValue());
Intent i = new Intent(getApplicationContext(), LocationDetailActivity.class);
i.putExtra(LOCATION_NAME, item.getID().getValue());
startActivity(i);
}
});
}
In the setOnItemClickListener I set the onItemClick method, start an Intent, and pass one parameter as the ID to the activity.
2. Define a Button, and Put the Activities in the OnClick Area
final Button button = (Button) findViewById(R.id.button_checkin);
button.setOnClickListener(new View.OnClickListener() {
publicvoid onClick(View view) {
String id = ((TextView) findViewById(R.id.location_id)).getText().toString();
Log.d(TAG,"Hitting the checkin button and get the location of id = "+ id);
…snip…
}
});
3. How We Receive the Message and Parameter
In the create lifecycle:
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
…snip…
Intent i = getIntent();
String id = i.getStringExtra(ChangeMeActivity.LOCATION_NAME);
…snip…
References:
http://www.androidhive.info/2011/10/android-listview-tutorial/
http://www.javacodegeeks.com/android/android-core
http://stackoverflow.com/questions/2965698/listview-setonitemclicklistener-and-setonitemselectedlistener-to-store-the-selec