views:

39

answers:

1

I have a ListView that displays every item in an array called, "Facts_Array". What I would like to do is display the count of the item clicked on. Right now I have this:

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
          Toast.makeText(getApplicationContext(), ((TextView) view).getText(),Toast.LENGTH_SHORT).show();

        }

When an item is clicked in the listview, it displays it using Toast. What I would like to change is what the toast displays. I would like it to find the number in which the item comes. If I click on the second item in the list, I want it to display number 2. Thanks!

A: 
  lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
      Toast.makeText(getApplicationContext(), ":D "+(position+1),Toast.LENGTH_SHORT).show();

    }
Cristian
Sweet! Thanks! That was a lot easier than I thought it would be!
Keenan Thompson
@Keenan Thompson: Then you should accept it.
Charlie Sheen
Yep. "You can accept an answer in 2 minutes" - says stackoverflow
Keenan Thompson