在我的程序中,我使用json從遠程SQL數據庫中獲取了一些字符串。這些項目(字符串)目前填充我的列表視圖。如果一個項目同時包含一個字符串和一個edittextfield,我想在listview中放置一個edittext字段。稍後我還想保存在edittext字段中輸入的文本,所以我需要能夠引用它。誰能幫我嗎?如何在同一個listitem中同時顯示字符串和edittext字段?
1
A
回答
2
你應該爲列表創建一個視圖,只要你喜歡它,這裏是例子。
home.xml
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/alert_dark_frame" >
</ListView>
</LinearLayout>
和一個更多的XML,你要充氣, list.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
在活動中使用這種方法,
LayoutInflater mlayoutinflator;
public void getlist(final ArrayList<contact> list){
// Get the list view
ListView listView = (ListView) findViewById(R.id.listView);
mlayoutinflator =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ArrayAdapter<contact> aa = new ArrayAdapter<contact>(this, R.layout.listitem,list){
@Override
public View getView(final int position, View convertView,ViewGroup parent)
{
if (null == convertView)
{
convertView = mlayoutinflator.inflate(R.layout.listitem, parent, false);
holder = new ViewHolder();
holder.value1 = (TextView)convertView.findViewById(R.id.textView1);
holder.value2 = (TextView)convertView.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.value1.setText(""+list.get(position).getName().trim());
holder.value2.setText(""+list.get(position).getNumber().trim());
convertView.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"));
intent.putExtra("sms_body", list.get(position).getName()+"-"+list.get(position).getNumber());
startActivity(intent);
}
});
return convertView;
}
};
listView.setAdapter(aa);
}
static class ViewHolder
{
private TextView value1;
private TextView value2;
}
2
嘿,這可能會幫助你
相關問題
- 1. 如何在同一行上向後顯示一個字符串?
- 2. 在EditText字段中提示texSize不同
- 3. 如何在同一個東西中顯示字符串和變量?
- 4. 如何在不同的文本字段中顯示時間段?
- 5. 如何在同一行上顯示連接字符串
- 6. 比較一個字符串和幾個不同的字符串
- 7. 如何在MATLAB中一起顯示字符串和數字?
- 8. 在Cococa中顯示一個字符串
- 9. SQL:從一個字段中選擇不同的子字符串
- 10. 如何在文本字段中顯示字符串變量python
- 11. 如何顯示一段時間的字符串
- 12. 如何在同一個TextView中設置一個字符串和一個double?
- 13. 以不同方式顯示字符串
- 14. CheckedListBox顯示不同的字符串c#
- 15. codeigniter如何在同一時間啓用段基址和查詢字符串url
- 16. 如何在Ruby控制器中同時記錄一個字符串和對象?
- 17. 如何用此字符串中的兩個不同字符替換第一個和最後一個字符「{0}」
- 18. 如何顯示不同顏色的WPF ListView中的字符串?
- 19. 在逗號和空格上同時分割一個字符串
- 20. MySQL同一個字母在一個字符串中的多個時間
- 21. 顯示字符串的列表,而不是一個顯示一個字符串
- 22. 替換。同在一個字符串
- 23. 如何在SSRS中總和SUM = 0時顯示字符串值
- 24. 如何使用hexdump同時顯示不同演示文稿中的字符
- 25. 如何在MIPS中的同一行中打印字符串和另一個字符串變量?
- 26. 如何在VB.NET中顯示字符串
- 27. 如何在php中顯示字符串?
- 28. 顯示「」在一個字符串輸出
- 29. 如何用數組替換字符串中的同一個字符串實例?
- 30. 在EditText中顯示密碼的最後一個字符
非常有幫助,我得到了大部分工作了。我仍然不知道如何做的唯一的事情就是引用我的文本框,這樣我就可以保存它們。 – HansStam 2012-03-05 05:09:48
你會有一個要添加到列表中的字符串列表。在上面的獲取列表方法中傳遞該列表,現在創建一個持有者類來保存所有視圖,如示例中所示,並且如果您遇到問題,請調用視圖項目,如holder.value1.setText(yourlist.getposition.getitem) – Rakshi 2012-03-05 05:24:46
你的班級的郵件我會修好,[email protected] – Rakshi 2012-03-05 05:26:08