How to click button inside method Adapter in RecyclerView?

喜你入骨 提交于 2020-02-23 07:19:44

问题


I am working on stripe-terminal-android-app, to connect to BBPOS 2X Reader device,

wanted to click-item from list,(recyclerView).

I am trying to do:

when list of devices appears(readers), I am checking if readers.size()==1, then click first-device from list,else show recyclerView();

I have very less experience in Android(coming from JS, PY), :)

After going through debugger to understand flow of program-running, I used F8 key, or stepOver the functions one by one,

and where value is assigned to convert in displayble-format in adapter as here.

public ReaderAdapter(@NotNull DiscoveryViewModel viewModel) {
    super();
    this.viewModel = viewModel;
    if (viewModel.readers.getValue() == null) {
        readers = new ArrayList<>();
    } else {
        readers = viewModel.readers.getValue();
        if(readers.size() == 1){
            Log.e(TAG, "readers.size() is 1 "+ readers.size());
        }

    }
}

then in ReaderHolder-file, values are bind() as

    void bind(@NotNull Reader reader) {
        binding.setItem(reader);
        binding.setHandler(clickListener);
        binding.executePendingBindings();
    }
}

I tried assigining button and manually clicking when only-one device appears, by clicing on reader[0], can't do that by findViewById inside Adapter file, to call onClick() method manually,

I tired another StackOverflow's answer but didn't understood, from here.

Main fragment is discovery-fragment,

how can I click first-device by checking readers.size()==1, then click onClick()?

my final-goal is to automate, whole stripe-terminal-payment process on android.

extra-info:

I am fetching data from python-odoo server, then using url, will open app through browser, (done this part), then device will be selected automatically as everytime-no any devices will be present except one,

so will automatically select that from recyclerView, then proceed.

I have asked for help in detailed way on GitHub-issues, and started learning Android's concepts for this app(by customizing stripe's demo app, which works great, but I wanted to avoid manually clicking/selection of devices).

来源:https://stackoverflow.com/questions/58825901/how-to-click-button-inside-method-adapter-in-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!