Create an interface
:
public interface OnDeleteListener {
public void onDelete(String message);
}
When you are initializing customadapter
send OnDeleteListener
as a parameter:
private OnDeleteListener mListener;
public customadapter(ArrayList<HashMap<String, String>> oslist,Context context, OnDeleteListener mListener) {
this.context = context;
this.oslist = oslist;
this.mListener = mListener;
}
then on delete button click
check for listener
to whether activate it or not:
btnDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//I want show YES NO dialog here
if(mListener != null)
mListener.onDelete("The message you want to show");
}
});
and finally initialize
adapter in your activity/fragment
and on listener invoke
show Dialog
:
customadaper mAdapter = new customadapter(ArrayList<HashMap<String, String>> oslist,Context context, new OnDeleteListener(){
@Override
public void onDelete(String msg){
//Show your dialog here
//msg - you can send any parameter or none of them through interface just as an example i send a message to show
showDialog(msg);
}
});
You can create a seperate function for code clearance and call it whenever you want to use
(also notice that, to create a custom dialog
you have to inflate
it {probably thats why you are getting an error}):
private void showDialog(String message){
// set the custom dialog components - text, image and button
inflater = mInflater.inflate(R.layout.your_custom_dialog, null, false);
TextView text = (TextView) inflater.findViewById(R.id.text);
text.setText(message);
ImageView image = (ImageView) inflater.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher); //line 115
AlertDialog.Builder mDialogBuilder = new AlertDialog.Builder(context);
mDialogBuilder.setView(viewFilterDialog);
mDialogBuilder.setCancelable(true);
mDialogBuilder.setTitle(mRes.getString(R.string.dialog_title_filter));
...
final AlertDialog mAlertDialog = mDialogBuilder.create();
mAlertDialog.show();
note: I have hardcoded this answer so any syntax error
can occur
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…