vivek_Android
vivek_Android

Reputation: 1697

Android LIst view

HI all,

First of all i want to know that what are the index of list view items??? is something like the index of array (a[0],a[1]....).

Actually i want to get the index of list item. it always showing me -1 here is the code.

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

      Object index = getListAdapter().getItem(position);

      Intent myIntent = new Intent(this, newsdisplay.class);
      //Create the view using FirstGroup's LocalActivityManager  
      View view = newsgroup.group.getLocalActivityManager()  
            .startActivity("show_city", myIntent  
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))  
            .getDecorView();  

      //Again, replace the view  
      newsgroup.group.replaceView(view);  
 } 

pls help me how to get the index of list view items and is this unique to other items??

Upvotes: 0

Views: 211

Answers (1)

Cheryl Simon
Cheryl Simon

Reputation: 46844

There are two different numbers associated with each item in the listView.

The position is the location of the item within the arrayAdapter.

The index is the location of the item within the visible ListView items.

Thus, for any given item, the position should stay constant over time, but the index will change as different items are visible.

It is not clear what you are trying to do with your code snippet, but the Object you call index should be the object at position within your ArrayAdapter, so a[position].

If the index of an item is -1, I would think that would mean it is not currently visible on the screen..

Upvotes: 1

Related Questions