Reputation: 2783
I'd like to show another List View 'B' after clicking a item of List View 'A'. I use onListItemClick event in Android 1.6 project.
public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this,
"You have selected " + lv_arr[position],
Toast.LENGTH_SHORT).show();
}
how to code it?
Upvotes: 2
Views: 2650
Reputation: 2783
I could see the List View by adding
<activity android:name=".WhiteListView"/>
in AndroidMainfest.xml.
Upvotes: 1
Reputation: 23179
If you want to stay on the same Activity and layout you could use a ViewSwitcher, which is designed for flipping between two views.
However I would strongly suggest that the click triggers a new local Activity via an Intent. This will have a new Layout containing your second ListView. This is because users will expect that having clicked and had the display significantly change, that pressing the back button will take them back to the original location in the app. As a general rule, any user action that changes the conceptual location in the application should be accompanied by an Activity change.
Upvotes: 1
Reputation: 208002
For example I call a new activity using Intents, with packed values added this way...
@Override
public void onListItemClick( ListView parent, View v, int position, long id) {
Intent lancon = new Intent(this, viewContact.class);
//lancon.putExtra("id", id);
//or
c.moveToPosition(position);
id = c.getInt(0);
c.close();
lancon.putExtra("id", id);
this.startActivity(lancon);
finish();
}
Then in the other class onCreate method I call:
this._id = this.getIntent().getLongExtra("id", 0);
Upvotes: 0
Reputation: 6824
How about try ExpandableListView. When you click on the groupview it expands to show childviews. It has a nice BaseExpandableListAdapter.
Upvotes: 0