开发者

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 a开发者_JS百科n item in the List View . How do I do that ??


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);


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜