开发者

Passing listView row positions through Intents to another class

I'm wondering how to pass a row position(pos) value from, say, a CHOICE_MODE_SINGLE list Activity(A) to another Activity(B) using Intents? (I want to change ActivityB to show another list depending on what row in ActivityA is clicked). Here's my code:

    final ListView listView = getListView();
    listView.setItemsCanFocus(false);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setOnItemClickListener(
             new android.widget.AdapterView.OnItemClickListener(){
                  @Override
                  public final void onItemClick(AdapterView<?> listView, View cell, int position, long id) {



                      Intent Courses = new Intent开发者_高级运维(this, ExpandableList.class);
                       Courses.putExtra(//I'm not sure what to put in here//)
             });



    private static final String[] GENRES = new String[] {"Barre","Buffumville","Hodges","Newton Hill"};

}     

THANKS :)


Courses.putExtra("position",position);

Then to get the position in the next activity:

getIntent.getExtras().getInt("position");


You can pass the position through the intent putExtra.

please see below Code.

 Intent Courses = new Intent(this, ExpandableList.class);
 Courses.putExtra("position",position)
 startActivity(Courses);

Now you can get this value in another activity like this.

 getIntent.getExtras().getInt("position");

It will return the integer position you passed from the first activity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜