当我从自定义对话框中退出时如何在父片段中更新我的 Listview
How to update my Listview in parent fragment when i dismiss from custom dialog
我有一个列表视图 setonlongclicklistner 来打开一个显示删除和取消的自定义对话框。
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Cursor c = (Cursor) sp.getItem(position);
int c_id = c.getInt(0);
String userid = c.getString(1) + c_id;
frag = new UserListDeleteFragment();
Bundle bundle = new Bundle();
bundle.putString("id", "" + c_id);
bundle.putString("userid", userid);
frag.setArguments(bundle);
frag.setCancelable(false);
frag.show(Lenderlist.this.getSupportFragmentManager(), "f");
return true;
}
});
下面是自定义对话框的代码,它将删除选定的列表项
public class UserListDeleteFragment extends DialogFragment {
TextView tv1,tv2;
Dialog d;
String user_id,ids;
MyDatabase m;
public UserListDeleteFragment() {
// Required empty public constructor
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
d=null;
m=new MyDatabase(getActivity());
AlertDialog.Builder ab=new AlertDialog.Builder(getActivity());
View v=getActivity().getLayoutInflater().inflate(R.layout.fragment_user_list_delete, null);
tv1= (TextView) v.findViewById(R.id.textviewbutton1);
tv2= (TextView) v.findViewById(R.id.textviewbutton2);
Bundle b=getArguments();
user_id = getArguments().getString("userid");
ids=getArguments().getString("id");
tv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean b;
m.open();
b=m.deleteTitle(ids);
m.close();
m.open();
m.deletesublist_user(user_id);
m.close();
if(b==true)
{
Toast.makeText(getActivity(),"Deleted",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getActivity(),"Not Deleted",Toast.LENGTH_SHORT).show();
}
d.dismiss();
}
});
tv2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
}
});
ab.setView(v);
d=ab.create();
return d;
}
}
当对话框 dismiss.Any 有解决方案时,我想从第一个片段更新我的列表视图。我在 android 中表现不佳。也很抱歉英语不好。提前致谢。
覆盖 UserListDeleteFragment 的 onDismiss 方法以调用列表适配器的 notifyDataSetChanged
我有一个列表视图 setonlongclicklistner 来打开一个显示删除和取消的自定义对话框。
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Cursor c = (Cursor) sp.getItem(position);
int c_id = c.getInt(0);
String userid = c.getString(1) + c_id;
frag = new UserListDeleteFragment();
Bundle bundle = new Bundle();
bundle.putString("id", "" + c_id);
bundle.putString("userid", userid);
frag.setArguments(bundle);
frag.setCancelable(false);
frag.show(Lenderlist.this.getSupportFragmentManager(), "f");
return true;
}
});
下面是自定义对话框的代码,它将删除选定的列表项
public class UserListDeleteFragment extends DialogFragment {
TextView tv1,tv2;
Dialog d;
String user_id,ids;
MyDatabase m;
public UserListDeleteFragment() {
// Required empty public constructor
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
d=null;
m=new MyDatabase(getActivity());
AlertDialog.Builder ab=new AlertDialog.Builder(getActivity());
View v=getActivity().getLayoutInflater().inflate(R.layout.fragment_user_list_delete, null);
tv1= (TextView) v.findViewById(R.id.textviewbutton1);
tv2= (TextView) v.findViewById(R.id.textviewbutton2);
Bundle b=getArguments();
user_id = getArguments().getString("userid");
ids=getArguments().getString("id");
tv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean b;
m.open();
b=m.deleteTitle(ids);
m.close();
m.open();
m.deletesublist_user(user_id);
m.close();
if(b==true)
{
Toast.makeText(getActivity(),"Deleted",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getActivity(),"Not Deleted",Toast.LENGTH_SHORT).show();
}
d.dismiss();
}
});
tv2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
}
});
ab.setView(v);
d=ab.create();
return d;
}
}
当对话框 dismiss.Any 有解决方案时,我想从第一个片段更新我的列表视图。我在 android 中表现不佳。也很抱歉英语不好。提前致谢。
覆盖 UserListDeleteFragment 的 onDismiss 方法以调用列表适配器的 notifyDataSetChanged