Reputation: 29
In my app I have a class that extends ListActivity and uses a ListView. My onListItemClick method just does not want to work. Inside the method it has to determine whether the item being clicked is Workout A or Workout B. Here is the code:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Long rowId = id;
Cursor cursor = mDbHelper.fetchNote(rowId);
String activity = cursor.getString(cursor.getColumnIndexOrThrow(StrongDbAdapter.WORKOUT_STATE));
if(activity == "Workout A"){
workoutAA = true;
}else if(activity == "Workout B"){
workoutAA = false;
}
if(workoutAA == true){
Intent i = new Intent(this, WorkoutEditA.class);
i.putExtra(StrongDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}else if(activity == "Workout B"){
Intent i = new Intent(this, WorkoutEditB.class);
i.putExtra(StrongDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_EDIT);
}
}
Upvotes: 0
Views: 128
Reputation: 66637
activity.equals( "Workout A")
. when string comparison use equals()
Another approach to avoid NullPointerException would be
"Workout A".equals(acitivty)
Upvotes: 2