Access to a TextView in Activity from Listview Adapter in android

☆樱花仙子☆ 提交于 2019-12-08 21:44:32
Vishwa

You can pass the view to adapter so that you can able to update it when ever needed. for that you need to add three TextView params in your adapter constructor. changes in adapter declare Textview variables in adapter class

TextView name,tel,mob;

public AdapterMoshtariItem(ArrayList<StructMoshtariItem> array,TextView txtInfoMoshtariName,TextView txtInfoMoshtariTel
                                    ,TextView txtInfoMoshtariMob) {
super(G.context, R.layout.moshtari_item, array);
this.name=txtInfoMoshtariName;
this.tel=txtInfoMoshtariTel;
this.mob=txtInfoMoshtariMob;
}

And change the fill data function

public void fill(final ArrayAdapter<StructMoshtariItem> adapter, final StructMoshtariItem item, final int position) {
        name.setText(item.id);
        tel.setText(item.name);
        mob.setText(item.tel);

        layoutRoot.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {


            }
        });

    }

Finally pass the textViews in adapter from class file.

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