android 如何从适配器中的接口方法获取响应

How to get response from interface method in adapter in android

所以这里我从适配器调用接口方法class。我想根据用户的输入更新 List。我将如何实现它?

适配器class:

public class ToDoListAdaptor extends SectionRecyclerViewAdapter < SectionHeader, Action, SectionViewHolder, ChildViewHolder > {

    @Override
    public void onBindChildViewHolder(final ChildViewHolder holder, final int sectionPosition, final int childPosition, final Action child) {

        Context mainActivityContext = Constants.getContext();

        if (action_id.equals("pain")) {

            if (mainActivityContext != null && mainActivityContext instanceof MainActivity) {
                interfaceAdapter = ((HealthVitalsFunction) mainActivityContext);
                boolean result = interfaceAdapter.openPainRecordDialog(context, dbHelper, action_id, action_cat_id, action_plan_id, action_name);

                if (result)
                    update(sectionHeaderList, childPosition);
            }

        }

    }
}

问题是当用户完成输入时我无法调用 update()。

编辑:

@Override
    public boolean openPainRecordDialog(final Context context, final DbHelper dbHelper, final String action_id, final String action_cat_id, final String action_plan_id, final String action_name) {


        Constants.painData=false;
        LayoutInflater layoutInflaterAndroid = LayoutInflater.from(context);
        final View mView = layoutInflaterAndroid.inflate(R.layout.pain_record, null);


        final AlertDialog dialog = new AlertDialog.Builder(context)
                .setView(mView)
                .setTitle("")
                .setPositiveButton(android.R.string.ok, null) 
                .setNegativeButton(android.R.string.cancel, null)
                .setCancelable(false)
                .create();




        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(final DialogInterface dialog) {

                Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                positiveButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Do something

                        if (dialog != null && ((AlertDialog) dialog).isShowing()) {
                            dialog.dismiss();
                        }

                        Constants.painData = true;


                    }
                });

                Button negativeButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
                negativeButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        // TODO Do something

                        if (dialog != null && ((AlertDialog) dialog).isShowing()) {
                            dialog.dismiss();
                        }

                        Constants.painData = false;
                    }

                });

            }
        });



        // show it
        dialog.show();

        return Constants.painData;

    }

I want to update the list based on the user's input.

如果您使用的是自定义对话框,请提供定义 onSuccess() 方法的自定义接口回调,并在您的调用 activity 中实现它,可用于更新 recyclerView。干杯:)