简体   繁体   中英

How to get response from interface method in adapter in android

So here I am calling the interface method from the adapter class. I want to update the List based on the user's input. How would I achieve it?

Adapter 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);
            }

        }

    }
}

The problem is that I am not able to call update() when user done with input.

edit:

@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.

If you are using a custom dialog, provide custom interface callback which defines onSuccess() method and implement it in your calling activity, which can be used to update the recyclerView. cheers :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM