PDA

View Full Version : Listview Help!



skewedToTheLeft
05-18-2012, 12:37 PM
Hi everyone. Let's say that I have two buttons (buttonA and buttonB) on the screen. When the user clicks buttonA I would like for a list of items to appear in the listview object. Likewise, when the user clicks buttonB I would like for the same listview object to populate a different list. How do I accomplish this?

Thanks

Piotr
05-21-2012, 03:17 AM
You can write two classes extending ArrayAdapter<> (also you can use standard)



class adapterA extends ArrayAdapter{...}


and



class adapterB extends ArrayAdapter{...}


And switch them from your interface (buttonA,buttonB)




buttonA.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View v) {
setListAdapter(mAdapterA);
}
});


buttonB.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View v) {
setListAdapter(mAdapterB);
}
});