我需要获取位于 ListView 某个位置的 TextView 的值。怎么做?
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 ->。
布局列表视图:
<?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"?>
<LinearLayout
xmlns: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 (QueryException 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();
}
}
}