Reputation: 13
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
Upvotes: 0
Views: 1244
Reputation: 149
replace this line:
if(name == ToDoActivity.myUser.tasks[i].getTaskName())
with this line:
if(name.equals(ToDoActivity.myUser.tasks[i].getTaskName()))
Upvotes: 0
Reputation: 35661
Use the "position" value that is being passed to you. It tells you which index was pressed.
Upvotes: 0
Reputation: 137332
If I understand what you're trying to do, you can simply use the position
argument of onItemClick
:
clickTask = position;
Upvotes: 1