Scooterboy
Lurker
Hey Folks I'm quite new to programming in general and am stuck on this matter. I've set up a listview to read from a database with 4 selections - Daily, Weekly, Monthly, and Yearly. I want to launch a different Activity for each one of the list items. When I click on an item it retrieves the correct string value but my 'if' statements are not recognizing them. Could someone point out where I'm going wrong? Here is the code for my onItemClickListener..........
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long itemId) {
String item = String.valueOf(itemId);
String vals[] = {item};
String cols[] = {"length_name"};
Cursor c = mDb.query("length", cols, "_id=?", vals, null, null, null);
if (c.moveToFirst()){
String item2 = c.getString(0);
if(item2 == "Daily") {
Intent myIntent = new Intent(getApplicationContext(), DateActivity.class);
startActivity(myIntent);
}
else if(item2 == "Weekly"){
Intent myIntent = new Intent(getApplicationContext(), MonthYearActivity.class);
startActivity(myIntent);
}
else if(item2 == "Monthly"){
Intent myIntent = new Intent(getApplicationContext(), MonthYearActivity.class);
startActivity(myIntent);
}
else if(item2 == "Yearly"){
Intent myIntent = new Intent(getApplicationContext(), YearActivity.class);
startActivity(myIntent);
}
}
c.close();
}
});
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long itemId) {
String item = String.valueOf(itemId);
String vals[] = {item};
String cols[] = {"length_name"};
Cursor c = mDb.query("length", cols, "_id=?", vals, null, null, null);
if (c.moveToFirst()){
String item2 = c.getString(0);
if(item2 == "Daily") {
Intent myIntent = new Intent(getApplicationContext(), DateActivity.class);
startActivity(myIntent);
}
else if(item2 == "Weekly"){
Intent myIntent = new Intent(getApplicationContext(), MonthYearActivity.class);
startActivity(myIntent);
}
else if(item2 == "Monthly"){
Intent myIntent = new Intent(getApplicationContext(), MonthYearActivity.class);
startActivity(myIntent);
}
else if(item2 == "Yearly"){
Intent myIntent = new Intent(getApplicationContext(), YearActivity.class);
startActivity(myIntent);
}
}
c.close();
}
});