Android 在Listview上一个选项已删除中,当我应用选项菜单时,删除任何列表项上的选项,它仅被删除最后一项我现在可以做什么?
在Android 在Listview上一个选项已删除中,当我应用选项菜单时,删除任何列表项上的选项,它仅被删除最后一项我现在可以做什么?,android,sqlite,android-listview,Android,Sqlite,Android Listview,在Listviewlast option deleted中,当我在任何列表项上应用选项菜单,delete option时,它只被删除了最后一项我现在可以做什么?当选择编辑选项时,它将选择或获取最后一项的信息,并出现类似的问题 final CharSequence[] gender = {"Edit","Delete"}; alert = new AlertDialog.Builder(StikiNotesActivity.this); fina
Listview
last option deleted中,当我在任何列表项上应用选项菜单,delete option时,它只被删除了最后一项我现在可以做什么?当选择编辑选项时,它将选择或获取最后一项的信息,并出现类似的问题
final CharSequence[] gender = {"Edit","Delete"};
alert = new AlertDialog.Builder(StikiNotesActivity.this);
final AlertDialog.Builder alert_del = new AlertDialog.Builder(StikiNotesActivity.this);
alert_del.setTitle("Confirmation !");
alert.setTitle("Options");
alert.setItems(gender,new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
if(which==0)
{
Toast.makeText(getApplicationContext(), "EditOpetion"+alist.get(0).sid, Toast.LENGTH_SHORT).show();
final Intent i = new Intent(StikiNotesActivity.this,FirstClass.class);
//String txt=new String();
i.putExtra("id",""+alist.get(position).sid);
startActivity(i);
}
else if(which==1)
{
AlertDialog.Builder alertDialog=new AlertDialog.Builder(StikiNotesActivity.this);
alertDialog.setTitle("Selected Subject will be deleted");
alertDialog.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
alist.remove(position);
adap.notifyDataSetChanged();
dialog.cancel();
}
});
alertDialog.setNegativeButton("Cancel", null);
alertDialog.show();
}
}});
请帮我解决这个问题?你可以这样做 1-单击Delete AlertDialog中的Ok按钮后,您必须获得
项目位置
,我建议您必须实现onItemClickListener
yourListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
alist.remove(position);
adap.notifyDataSetChanged();
}
});
希望这能帮助你从哪里得到这个职位?
else if(which==1){
AlertDialog.Builder alertDialog=new AlertDialog.Builder(StikiNotesActivity.this);
EditText txtPosition = new EditText(YourContext);
alertDialog.setView(txtPosition);
alertDialog.setTitle("Selected Subject will be deleted");
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//get the position from txtPosition
int position = Integer.parseInt(txtPosition.getText().toString());
alist.remove(position);
adap.notifyDataSetChanged();
dialog.cancel();
}
});
alertDialog.setNegativeButton("Cancel", null);
alertDialog.show();
}