wangz
wangz

Reputation: 61

check onItemclick(Array adapter) by value not by position

i know how to onItemClick works with position, but is it possible by the list value?? Fog eg. we have list of custom Array list(arraylist):

arraylist(new info("a","1"));
arraylist(new info("b","2"));
arraylist(new info("c","3"));

and in info.class:

String letter,number;
info(String t1,String t2){
letter=t1;
number=t2;
}

customAdapter(u know this well :)..)

Now, i know how to use condition with position of list: (under onItemclick function)

switch(position){
case 0:blah blah...
case 1:blah blah...
case 2:blah blah..
}

but is there a way to check the condition with the value..like this:

if(letter==a)
blah blah..
if(letter==b)
blah blah..

plse help.. sorry if it confuse you..but i am weak at explaining..

Upvotes: 1

Views: 48

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

Using switch()

arraylist.get(position) : get Info object

arraylist.get(position).letter : get the value of letter

switch(arraylist.get(position).letter){
  case "a":
  break;
  case "b":
  break;
  case "c":
  break;
}  

or

String value =arraylist.get(position).letter;
if (value.equals("a")){}
else if(value.equals("b")){}
else if(value.equals("c")){}

Upvotes: 2

Related Questions