0

This is some lines from my code:

vFlipper = (ViewFlipper) findViewById(R.id.viewflipper);<BR>
listView = (ListView) findViewById(R.id.firstlayout);<BR>
listView.setAdapter(stationaryAdapter);

List of object and when i click on them I get more information about every object. At this moment it works as it should do. But when i click on a button and it should read in som other objects and but a different layout to it the clickable feature stops to work.

On click these line is read:

vFlipper.setDisplayedChild(1);<BR>
listView = (ListView) findViewById(R.id.secondlv);<BR>
listView.setAdapter(mobileAdapter);

Without changing the layout it works with the new list.

Someone have a clue?

Mehdi
  • 1,494
  • 5
  • 33
  • 53
  • Sorry for the fuzziness. The question is why OnItemClickListener stops working when I change the layout on my listview –  May 03 '12 at 07:52

1 Answers1

0

When you are calling the adapter to get the item at the position you've clicked "adapter.get(position)", you are probably still using the first adapter instead of the second.

what you should be doing is, for the first layout:

listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,View view, int position, long id) {
stationaryAdapter.getItem(position));

}
});

for the second layout:

listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,View view, int position, long id) {
mobileAdapter.getItem(position));

}
});
eoghanm
  • 329
  • 1
  • 9
  • I did try this, but I figured out that when changing to mobileAdapter there´s no call to OnItemClickListener. I also figurered out that when changing layout with the viewFlipper all works fine except that I can not use the layout I want. –  May 03 '12 at 08:17
  • you should probably just use two listviews and hide the other when you want the other one to be visible then – eoghanm May 03 '12 at 12:41
  • Did go with multiple ListViews even if I will have duplicate code, which I hate. But it works now so it have to be this way. Thanks for your time! –  May 03 '12 at 14:25