开发者

ListView - Index and Position Behavior upon restart()

I am using a ListView with an ArrayAdapter that holds objects. When I select an item, I am capturing the position and index of the selected item. If I scroll down prior to selection, the position and index represent the location of the item in the list. Selecting that items takes me to another activity. When I use the back button to return to the list, it 开发者_如何学运维seems that the ListView gets a new position and index for the visible items.

As a result, I can't figure out how to reference the selected item during the restart() of the ListView Activity. I have tried to capture position and index, but as I've said, they change upon returning to the Activity.

Is my understanding of the ListView "redraw" correct? Does it renumber my items based on what's visible? -When in the life cycle is getView() called? Is there a way to force an update to the ListView so that my captured index still points to the same object?

Thanks, Jason


If you have the same elements in your ListView you will have the same position all the time, when you click an Item...

    @Override
    protected void onListItemClick(ListView l, View v, final int position, long id) {
        super.onListItemClick(l, v, position, id);
Toast.makeText(this, "This is the Item " + position + " of my listView",
                Toast.LENGTH_LONG).show();
        });

the same in you getView() function...

  public View getView(int position, View convertView, ViewGroup parent) {
    Toast.makeText(this, "This is the Item " + position + " of my listView",
                        Toast.LENGTH_LONG).show();          
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜