tôi tạo ra các DialogFragment sau bắt nguồn từ tài liệu Android:Làm thế nào để thực hiện hành động sau DialogFragment nút tích cực nhấp
public class PayBillDialogFragment kéo dài DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
final Bundle b = this.getArguments();
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Paga bollettino")
.setPositiveButton("Paga", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton("Cancella", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Từ một Fragment (một ListFragment), khi một hàng của danh sách được nhấn vào DialogFragment sẽ được mở và sau khi nhấn nút tích cực của DialogFragment tôi muốn có thể loại bỏ hàng đã chọn của ListFragment và cũng gọi một phương thức để thực hiện một hành động từ xa liên quan đến việc loại bỏ. tôi thực hiện các ListFragment như sau:
public static class ListFragment extends android.support.v4.app.ListFragment {
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
public static final String ARG_SECTION_NUMBER = "section_number";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.list_fragment_view,
container, false);
ListView lv = (ListView)rootView.findViewById(android.R.id.list);
}});
adapter=new ArrayAdapter<String>(this.getActivity(),
android.R.layout.simple_list_item_1,
listItems);
setListAdapter(adapter);
return rootView;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
//opening the dialogfragment
}
}
}
Những gì tôi không biết là làm thế nào để xử lý các hành động sau khi click vào nút tích cực của DialogFragment. Bạn có thể giúp tôi được không?
EDIT: để làm rõ, đây là quy trình làm việc: nhấp vào danh sách -> hiển thị DialogFragment -> sau khi nhấp vào DialogFragment xóa phần tử khỏi danh sách.
Tôi không hiểu. Làm cách nào để tôi có thể xóa các phần tử khỏi arraylist/arrayadapter khỏi phương thức onClick? – Raffo