我的阵列:
public String[] trainingstage = {"Hello","Hello 2"};
ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,androID.R.layout.simple_List_item_1,trainingstage);setlistadapter(adapter);ListVIEw ListVIEw = getListVIEw();ListVIEw.setonItemClickListener(this);
OnItem:
public voID onItemClick(AdapterVIEw<?> parent,VIEw vIEw,int position,long ID) { switch (position) { //untrained case 0: //here the text in the ListvIEw should change from "Hello" to "BYE" case 1: //here the text in the ListvIEw should change from "Hello 2" to "BYE 2" }
感谢帮助!
解决方法 你可以像这样实现你想要的:public voID onItemClick(AdapterVIEw<?> parent,long ID) { TextVIEw tv = (TextVIEw)vIEw.findVIEwByID(androID.R.ID.text1); switch (position) { //untrained case 0: //here the text in the ListvIEw should change from "Hello" to "BYE" tv.setText("BYE"); break; case 1: //here the text in the ListvIEw should change from "Hello 2" to "BYE 2" tv.setText("BYE 2"); break; } }
什么是androID.R.ID.text1
> ArrayAdapters构造函数使用androID.R.layout.simple_List_item_1 xml布局作为其第二个参数,此布局有一个子项 – 带有ID androID.R.ID.text1的TextVIEw.
总结以上是内存溢出为你收集整理的android – 更改列表视图的文本,由ArrayAdapter填充全部内容,希望文章能够帮你解决android – 更改列表视图的文本,由ArrayAdapter填充所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)