Karthik Ragubathy
Karthik Ragubathy

Reputation: 1

Passing Which ListView Item was Clicked to the Next Screen - Android

I have a ListView in Screen 1 where I have a few items . The User Clicks on an item in the Listview and Screen2 pops up . But What appears in Screen2 depends on what item was clicked in Screen 1

For Ex - User Clicks A in Screen 1 - Words starting from A come up in Screen 2

lv.setOnItemClickListener(new OnItemClickListener() {
     public void onItemClick(AdapterView<?> parent, View view,
         int position, long id) {

         // When clicked, Open the Next Screen
         Intent r=new Intent(Dummy.this ,CricksList.class );
         r.putExtra("extra", id);
         startActivityForResult(r, position);
         }

I have passed the item which was clicked on . But I want to Display on Screen 2 what the user clicked on - as an item in the List View . How do I do that ??

Upvotes: 0

Views: 2160

Answers (3)

ud_an
ud_an

Reputation: 4921

Try to create the other activity which displays the clicked item. Then, call the second activity on click.

Upvotes: 0

Preeti S
Preeti S

Reputation: 21

Create another activity and put code like this in it.....

TextView textview = (TextView) findViewById(R.id.myEditText);
String Name = getIntent().getStringExtra("extra");
textview.setText(Name);

Upvotes: 2

Pentium10
Pentium10

Reputation: 207912

Use the extra field from the receiving intent, and based on that, lookup the record in your data source(database, contentprovider, array) and inflate a view that suit your needs.

Upvotes: 0

Related Questions