java– 如何在列表视图中获取textview的值?

java– 如何在列表视图中获取textview的值?,第1张

概述我需要获取TextView的值,该TextView位于ListView的某个位置.怎么做?MyJava代码:protectedvoidonListItemClick(ListViewl,Viewv,intposition,longid){super.onListItemClick(l,v,position,id);TextViewtxtTechCharacteristic=(TextView)findViewById

我需要获取TextVIEw的值,该TextVIEw位于ListVIEw的某个位置.怎么做?

MyJava代码:

protected voID onListItemClick(ListVIEw l, VIEw v, int position, long ID) {    super.onListItemClick(l, v, position, ID);    TextVIEw txtTechCharacteristic = (TextVIEw) findVIEwByID(R.ID.techCharacteristic);    TextVIEw txtTechCharacteristicname = (TextVIEw) findVIEwByID(R.ID.techCharacteristicname);}

这是我的TextVIEw – >.

布局ListVIEw:

 <?xml version="1.0" enCoding="utf-8"?>    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical" androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent">    <relativeLayout         androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content">        <include layout="@layout/simple_back_action_bar" />    </relativeLayout>    <ListVIEw        androID:ID="@+ID/androID:List"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent"        androID:padding="10dp"        androID:textSize="16sp"/></linearLayout>

布局行:

<?xml version="1.0" enCoding="utf-8"?><linearLayoutxmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:orIEntation="vertical"><TextVIEw androID:ID="@+ID/techCharacteristic"         androID:textSize="20sp"         androID:textStyle="bold" androID:layout_wIDth="fill_parent"         androID:layout_height="fill_parent"/><TextVIEw androID:ID="@+ID/techCharacteristicname"         androID:textSize="15sp"               androID:layout_wIDth="wrap_content"         androID:layout_height="fill_parent"/></linearLayout>

填充ListVIEw的代码是在异步方法中完成的.它是:

public class PopulateTechCharacteristicList extends        AsyncTask<Integer, String, Integer> {    ProgressDialog progress;    Context context;    public PopulateTechCharacteristicList(Context context) {        this.context = context;    }    protected voID onPreExecute() {        progress = ProgressDialog.show(TechCharacteristicList.this,                getResources().getString(R.string.Wait), getResources()                        .getString(R.string.LoadingOperations));    }    protected Integer doInBackground(Integer... paramss) {        ArrayList<TechCharacteristic> arrayTechChar = new ArrayList<TechCharacteristic>();        TechCharacteristicWSQuerIEs techCharWSQuerIEs = new TechCharacteristicWSQuerIEs();        try {            arrayTechChar = techCharWSQuerIEs                    .selectTechCharacteristicByAsset(asset);            for (TechCharacteristic strAux : arrayTechChar) {                HashMap<String, String> temp = new HashMap<String, String>();                temp.put("cod", strAux.getTechCharacteristic() + " - "                        + strAux.getTechCharacteristicname());                temp.put("value",                        "Valor: " + strAux.getTechCharacteristicValue());                List.add(temp);            }        } catch (@R_403_5962@Exception e) {            e.printstacktrace();            return 0;        }        return 1;    }    protected voID onPostExecute(Integer result) {        if (result == 1) {            SimpleAdapter adapter = new SimpleAdapter(                    TechCharacteristicList.this, List,                    R.layout.techcharacteristic_rows, new String[] { "cod",                            "value" }, new int[] { R.ID.techCharacteristic,                            R.ID.techCharacteristicname });            setlistadapter(adapter);            progress.dismiss();        }    }}

解决方法:

onclick已将父视图传递为“v”

只是用

TextVIEw txtTechCharacteristic = (TextVIEw) v.findVIEwByID(R.ID.techCharacteristic);String txt = txtTechCharacteristic.getText();
总结

以上是内存溢出为你收集整理的java – 如何在列表视图中获取textview的值?全部内容,希望文章能够帮你解决java – 如何在列表视图中获取textview的值?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1111641.html

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

发表评论

登录后才能评论

评论列表(0条)

保存