Я пытаюсь удалить OnClick из Custom Dialog и обновить элемент, нажатый из RecyclerView.
final Dialog rightDialog = new Dialog(context1);
...
TextView textOKRight = (TextView) rightDialog.findViewById(R.id.text_ok);
textOKRight.setText("NEXT");
textOKRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// MainAdapter.ViewHolder ccd = new MainAdapter.ViewHolder(itemView, listener);
// ccd.removeCaller();
rightDialog.dismiss();
}
});
rightDialog.show();
MainAdapter
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder>{
..
private static ViewHolder.IndividualClickListener mListenerCallback;
private static ViewHolder.IndividualClickListener mListener;
private MainAdapter mMyAdapter;
public AnimatorSampleActivity animatorActivity;
public MainAdapter(Context context, ArrayList<Question> dataSet) {
mContext = context;
questions = dataSet;
...
}
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public IndividualClickListener mListener;
...
public ViewHolder(View itemView, IndividualClickListener listener) {
super(itemView);
mListener = listener;
image = (ImageView) itemView.findViewById(R.id.imageMic);
imageOne = (ImageView) itemView.findViewById(R.id.imageOne);
text = (TextView) itemView.findViewById(R.id.text);
itemView.setOnClickListener(this);
image.setOnClickListener(this);
}
//////THIS IS THE METHOD I WOULD LIKE TO CALL FROM THE DIALOG///////
public void removeCaller() {
mListener.remove1(getLayoutPosition());
Log.d(TAG, "Main Adapter Called remove1 from removeCaller()");
}
@Override
public void onClick(View v) {
if (v instanceof ImageView) {
} else {
}
}
public interface IndividualClickListener {
void onTomato(ImageView callerImage, int position);
void onPotato(View caller, int position);
void remove1(int position);
void onDialogClick(TextView textOKRight);
}
}
@Override
public int getItemCount() {
return questions.size();
}
@Override
public void onBindViewHolder(final MainAdapter.ViewHolder holder, final int position) {
Question currentQuestion = questions.get(position);
///I CREATED A DIALOG HERE, Dialog.Builder AND IM ABLE TO HAVE THE DIALOG DIMISS AND REMOVE THE ITEM, BUT I CANT FIGURE OUT HOW TO DO IT FROM MY CUSTOM DIALOG OUTSIDE MainAdapter////
Picasso.with(mContext).load(currentQuestion.drawableId).into(holder.getImageView());
Picasso.with(mContext).load(currentQuestion.iconId).into(holder.getImageView1());
holder.getImageView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v instanceof ImageView) {
//holder.removeCaller();
//mAdapterCallback.remove1(position);
mListenerCallback.onTomato((ImageView) v, position);
Log.d(TAG, "Main Adapter Called remove from OnBindViewHolder"+""+position);
}else{
mListenerCallback.onPotato((ImageView) v, position);
}
}
});
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_list_item, parent, false);
final MainAdapter.ViewHolder vh = new ViewHolder(v, new MainAdapter.ViewHolder.IndividualClickListener(){
@Override
public void onTomato(ImageView callerImage, int position) {
Log.d(TAG, "Main Adapter Called OnTomato OnCreateVIewHolder");
}
@Override
public void onPotato(View caller, int position) {
}
@Override
public void remove1(int position) {
questions.remove(position);
notifyItemRemoved(position);
Log.d(TAG, "Main Adapter Called remove1 from OnCreaterViewHolder" + position);
}
@Override
public void onDialogClick(TextView textOKRight) {
}
});
return vh;
}
public interface callerCallBack{
.....
}
}
UPDATE
public class NewCustomDialog extends Dialog {
private static dialogCallerCallBack mdialogCallerCallBack;
private MainAdapter.ViewHolder.IndividualClickListener listener;
public NewCustomDialog(Activity a, dialogCallerCallBack mdialogCallerCallBack, Context dContext, TextView dialogTitleRight, TextView rightMsgRight, TextView rightAnswerRight, TextView textOKRight, ImageView imageRight) {
super(a);
this.dialogTitleRight = dialogTitleRight;
this.rightAnswerRight = rightAnswerRight;
this.rightMsgRight = rightMsgRight;
this.textOKRight = textOKRight;
this.imageRight = imageRight;
this.dContext = dContext;
//pass this so it can be used
this.mdialogCallerCallBack=mdialogCallerCallBack;
this.c =a;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//final Dialog rightDialog = new Dialog(context);
getWindow().setBackgroundDrawable(new ColorDrawable(0));
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mt_alert_right_dialog);
setCanceledOnTouchOutside(false);
setCancelable(false);
TextView dialogTitleRight = (TextView) findViewById(R.id.txt_title);
TextView rightMsgRight = (TextView) findViewById(R.id.right_msg);
TextView rightAnswerRight = (TextView) findViewById(R.id.right_answer);
final TextView textOKRight = (TextView) findViewById(R.id.text_ok);
ImageView imageRight = (ImageView) findViewById(R.id.image);
textOKRight.setText("NEXT");
textOKRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mdialogCallerCallBack.onDialogClick(((TextView)textOKRight));
}
});
}
public interface dialogCallerCallBack{
void onDialogClick(TextView textOKRight);
}
}
Ошибка
Process: jp.wasabeef.example.recyclerview, PID: 28523
java.lang.NullPointerException at jp.wasabeef.example.recyclerview.NewCustomDialog$1.onClick(NewCustomDialog.java:82)
строка 82
mdialogCallerCallBack.onDialogClick(((TextView)textOKRight));