setText从ListView项目到TextView(在ListView之外)

时间:2016-02-12 11:09:27

标签: android listview

可以从LISTITEM访问一个TEXTVIEW(在LISTITEM / LISTVIEW外面)

enter image description here

你可以在图像中看到我想从listitem中的按钮改变textview的值(当前值是“Rs.97”)(即“+”和“ - ”按钮)

这里是我的代码:

enter image description here

1 个答案:

答案 0 :(得分:2)

  

制作如下界面:

   public interface ChangeItemInterface {

        public void doChange(String anyValue);

    }

在适配器中,

  

初始化接口对象,如:

ChangeItemInterface changeItemInterface;
  

在适配器构造函数中,

this.changeItemInterface = context;
  

在适配器中,从任何视图单击:

AnyView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                 this.changeItemInterface.doChange("AnyValue");
                 // It will go to the Your Activity Overided method which is explained below this


            }
        });
  

在您的活动中实现此界面,如:

     public class YourActivity extends Activity implements ChangeItemInterface{

        /// You'll get override method of your interface, here your call back will come when from adapter click happen
         @Override
            public void doChange(String anyValue) {

              /// Here you can update any value in your activity !
            }

        }

希望这能帮助您解决问题!