0

For some reason this only returns the name of the first item in the list no matter which item I click. I am not sure why it isn't returning the proper name. Basically I just want to find the name so I can search the list for that name so I can find its location in the array.

    myTask.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text
            String name = ((TextView)view).getText().toString();
            for (int i = 0; i < ToDoActivity.myUser.taskCount; i++){
                if(name == ToDoActivity.myUser.tasks[i].getTaskName())
                    clickTask = i;
            }
            Intent myIntent = new Intent(view.getContext(), TaskEdit.class);
            view.getContext().startActivity(myIntent);
        }

Thank You Dlong

user433047
  • 13
  • 6

3 Answers3

1

If I understand what you're trying to do, you can simply use the position argument of onItemClick:

clickTask = position;
MByD
  • 135,866
  • 28
  • 264
  • 277
  • doesn't that refer to the position in the list not the position in the array? What if I sorted the list to only display certain items then the position variable would correspond to the right position in the array right? – user433047 Apr 07 '12 at 19:53
0

Use the "position" value that is being passed to you. It tells you which index was pressed.

Kuffs
  • 35,581
  • 10
  • 79
  • 92
0

replace this line:

if(name == ToDoActivity.myUser.tasks[i].getTaskName())

with this line:

if(name.equals(ToDoActivity.myUser.tasks[i].getTaskName()))
JRaymond
  • 11,625
  • 5
  • 37
  • 40
Gandhi Ishan
  • 149
  • 4
  • While technically true, Binyamin Sharet's answer is more along the lines of what the user should be doing – JRaymond Apr 07 '12 at 19:26