【问题标题】:How to change the text of button in other adapter? Android如何更改其他适配器中按钮的文本?安卓
【发布时间】:2017-02-20 07:18:11
【问题描述】:

我已经创建了一个适配器并且有一个按钮,并且我有一个 setOnClickListener(),我想在其中更改其他适配器中按钮的文本。

我该怎么做?

适配器 1 中的按钮:

accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setTitle("Confirm");
    builder.setMessage("Are you sure?");
    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
        // Do nothing but close the dialog
        // TODO Auto-generated method stub
        mAccept = true;
        if (mAccept) {
            count++;
            if(count==1) {
                accept.setText("Dispatching");
                //buyer:requesting---->waiting

            }
            if(count==2) {
                accept.setText("Dispatched");
            }

适配器 2 中的按钮:

viewHolder.mBuyButton.setOnClickListener(new View.OnClickListener(){}

用户点击适配器 1 中的按钮后,按钮变为“正在调度”,我希望适配器 2 中的按钮文本变为“等待”。

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 在适配器内传递您的按钮引用。
  • 代码 ??????

标签: android button adapter


【解决方案1】:

当您在活动中启动按钮后调用适配器时,将 Button 变量传递给其中。

例如

按钮按钮=findViewById(R.id.button);

假设 Adapter 是你的 addpter 类而不是

适配器适配器=新适配器(button,all_other_parameters_here);

比适配器类 在 onclick 监听器使用中,

button.setText("你的文本或变量");

或者你可以在 onlicklistner 上实现

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2015-02-02
    相关资源
    最近更新 更多