I have a GridView with multiple items, but the items must be kept selected once the the onClickListener is called.How can i achive this?
I’v already tried v.setSelected(true) but it doesnt seem to work.
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Toast.makeText(Project.this, "Red" + position,
// Toast.LENGTH_SHORT).show(); //position = al catelea element
v.setPressed(true);
if (bp == 2) {
if (position == 0) {
Square.setSex(R.drawable.girl_body2v);
Square2.setHair(R.drawable.girl_hair_01v);
SquareAccesories.setAcc(R.drawable.girl_accessories_01v);
SquareEyes.setEyes(R.drawable.eyes_1v);
SquareLips.setLips(R.drawable.lip_1v);
Square3.setDress(R.drawable.girl_tops_01v);
SquareShoes.setShoes(R.drawable.girl_shoes_01v);
SquarePants.setPants(R.drawable.girl_bottom_01v);
setS(2);
This is a small part of the code for the onClickListener because i have lots of cases.
The concept that you want to achieve is possible, but not like the way you are working now.
The best and easiest solution would be to keep track of the states of the clicked items and give them the correct layout inside the adapter. I have set up a little example:
Activity
GridObject
Main.xml
list_item_icon_text