Reputation: 21
I have created an android application. In that application when I click the listview item it should display in the another listview in the same layout.
Is this possible in android?
Upvotes: 0
Views: 199
Reputation: 15089
Well, quick snippet:
public Activity1 extends Activity {
ListView listView;
@Override
protected void onCreate(Bundle b) {
// stuffs here
....
// ListView event
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("SelectedString", listView.getItemAtPosition(position));
startActivity(intent);
}
});
}
}
public Activity2 extends Activity {
ListView listView;
@Override
protected void onCreate(Bundle b) {
// stuffs here
....
String valueFromActivity1 = getIntent().getString("SelectedString");
// ok now, u've got value from Activity1, do whatever w/ it
}
}
Upvotes: 2
Reputation: 311
No you have to make intent and pass the variables of the current selected item of the listview to that intent and display the dynamic listview for that Item
Upvotes: 0