android – 更改列表视图的文本,由ArrayAdapter填充

android – 更改列表视图的文本,由ArrayAdapter填充,第1张

概述有没有办法更改listview中的文本,由ArrayAdapter填充? 我的阵列: public String[] trainingstage = {"Hello", "Hello 2"}; ArrayAdapter ArrayAdapter<String> adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item 有没有办法更改ListvIEw中的文本,由ArrayAdapter填充?

我的阵列:

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填充所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1125239.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存