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();
}
}
}