我有一个asynctask listview,显示姓名,电子邮件,电话号码。我在对话框中更新所选项目的名称,但它将其显示为数组。如何使它显示特定值,例如“名称”?
默认值:姓名:name1,电子邮件:email@email.com,mobile:000 当我打开对话框时,textview将显示{email = email,name = name,id = c201,mobile = 000}
我希望这能在textview上显示'name'
ListView lv = getListView();
// Listview on item click listener
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {
// getting values from selected ListItem
final String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();
// Create custom dialog object
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.custom);
// Set dialog title
dialog.setTitle("Custom Dialog");
// set values for custom dialog components - text, image and button
final TextView text = (TextView) dialog.findViewById(R.id.name_label);
text.setTextColor(Color.GREEN);
dialog.show();
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
String itemValue = (lv.getItemAtPosition(position).toString());
text.setText(itemValue);
}
public void onFinish() {
}
}.start();
}
答案 0 :(得分:2)
你的listview必须绑定了一个适配器,textview上的文本来自一个数组,所以你应该从你的数组数据中获取每个字符串,而不是直接从listview获取。
替换:
String itemValue = (lv.getItemAtPosition(position).toString());
使用:
String itemValue = (YourArray[position].toString());//YourArray is your data array for showing text on textview
答案 1 :(得分:1)
从Listview获取数据
您可以使用onItemClick
例如。 Arraylist listArrayObj.get(position)
JsonArray listJsonarrayArrayObj.get(position)
String []比yourStrArra[position]
建议
的 DO NOT 强>
final String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
String cost = ((TextView) view.findViewById(R.id.email))
.getText().toString();
String description = ((TextView) view.findViewById(R.id.mobile))
.getText().toString();
<强> DO 强>
直接从传入适配器
的Array中获取数组的值