ListView with a dynamic intents that change a TextView and WebView on each call

后端 未结 2 805
轻奢々
轻奢々 2021-01-28 19:07

Activity that is sending the putExtra()

@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
    super.onListIt         


        
2条回答
  •  离开以前
    2021-01-28 19:55

    To accomplish that, you would, instead of using a different Intent for each list item, call the same Activity with the same Intent, but pass extras along with it.

    Let's say, for instance, that you want to pass a different String depending on which list item is clicked. You would want to

    myIntent.putExtra(String key, String value);
    startActivity(myIntent);
    

    The Activity that you start with this Intent will then be able to grab these extras in its onCreate() using

    Bundle extras = getIntent().getExtras();
    

    and access the extras you put in the Intent using the methods outlined here. This way you can use a single Activity for all list items but have the Activity display different information based on the extra values.

提交回复
热议问题