My fragment Note
is accessing the delete method of Fragment To-do List and not performing its own line of code. How can I rectify it? The rest of the methods work correctly.
Where is it going wrong?
Code of delete in fragment Note:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int listpos = info.position;
String io = list1.getItemAtPosition(listpos).toString();
StringTokenizer s=new StringTokenizer(io);
if (item.getTitle()=="Delete") {
ArrayList<String> all = new ArrayList<String>();
while (s.hasMoreTokens()) {
all.add(s.nextToken());
}
Toast.makeText(getContext(), all.get(0).toString(), Toast.LENGTH_SHORT).show();
String query = "delete from notes where heading = '"+all.get(0).toString()+"';";
database.execSQL(query);
//database.close();
Intent n = new Intent(getContext(), MainActivity.class);
startActivity(n);
}
Code of fragment To-doList:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int listpos = info.position;
String io = list.getItemAtPosition(listpos).toString();
StringTokenizer s=new StringTokenizer(io);
if (item.getTitle()=="Delete") {
ArrayList<String> al = new ArrayList<String>();
while (s.hasMoreTokens()) {
al.add(s.nextToken());
Toast.makeText(getContext(), al.get(0).toString(), Toast.LENGTH_SHORT).show();
String query1 = "delete from todolist where elist = '" + al.get(0).toString() + "';";
database.execSQL(query1)
Intent n = new Intent(getContext(), MainActivity.class);
startActivity(n);
}