1
我有一個Android活動,顯示日誌條目列表(使用遊標適配器和列表視圖)。當其中一個條目被觸動時,它會將一個意圖(包含日誌細節的捆綁對象作爲字符串傳遞給另一個活動)啓動。新的活動應該在我創建的自定義TableView xml文件中顯示詳細信息,但我無法弄清楚如何將捆綁字符串綁定到在TableView的TextView中定義的id。將字符串綁定到TableView/TextView ID
我已經包含了大部分我的代碼,所以你可以看到我想要完成的事情。
VIEWENTRY類:
public class ViewEntry extends Activity{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.view_list);
setTitle(R.string.view_entry_title);
TableView lv= (TableView)findViewById(R.id.viewlayout);
Bundle extras = getIntent().getExtras();
if (extras != null){
String date = extras.getString(plbDbAdapter.KEY_DATE);
String ident = extras.getString(plbDbAdapter.KEY_IDENT);
String type = extras.getString(plbDbAdapter.KEY_TYPE);
String from = extras.getString(plbDbAdapter.KEY_FROM);
String to = extras.getString(plbDbAdapter.KEY_TO);
String remark = extras.getString(plbDbAdapter.KEY_REMARK);
String[] from = new String[] { "date_h", "ident_h", "type_h", "from_h", "to_h", "remark_h"};
int[] to = new int[] { R.id.v_date, R.id.v_ident, R.id.v_type, R.id.v_from, R.id.v_to, R.id.v_remark };
ArrayAdapter details = new ArrayAdapter(this, R.layout.view_list, from, to);
setAdapter(details);
List<HashMap<String, String>> fillList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("date_h", date);
map.put("ident_h", ident);
map.put("type_h", type);
map.put("from_h", from);
map.put("to_h", to);
map.put("remark_h", remark);
fillList.add(map);
SimpleAdapter viewadapt = new SimpleAdapter(this, fillList, R.layout.view_list, from, to);
lv.setAdapter(viewadapt);
}
}
這裏是view_list.xml我試圖綁定到:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/viewlayout"
android:stretchColumns="1">
<TableRow>
<TextView
android:gravity="left"
android:text="Date:"
android:padding="3dip" />
<TextView
android:id="@+id/v_date"
android:gravity="right"
android:padding="3dip" />
我知道我想要做的是不對的,但希望它有助於說明我的意圖。
嗯,看起來像我的XML得到切斷,但你可以看到第一個ID(v_date)我想結合。 – Charles 2010-08-13 21:24:30