【发布时间】:2017-10-28 11:06:39
【问题描述】:
我的片段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);
}
片段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);
}
【问题讨论】:
-
FragmentNote & todolist 扩展了什么? @AkshraGupta,他们也有相同的活动吗?如果是,请参阅:stackoverflow.com/questions/5297842/… -
@AshishRanjan 感谢您提供链接。虽然它没有回答我的问题,但它把我引向了另一个我找到答案的问题。
-
在使用片段时,我不得不使用 android.view.MenuItem,而不是使用 MenuItem。
标签: java android android-fragments