有人可以告訴我如何在不使用ListActivity的情況下創建ListView?如何在沒有ListActivity的情況下創建ListView
我需要把我的佈局其他幾個視圖,我希望佈局沒有完全佔用的ListView。它必須是佈局的一部分,而不是整個佈局。我想創建一個正常的活動。
代碼片段:
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.savings);
//...
ListView lvPoupanca = (ListView)this.findViewById(R.id.lvPoupanca);
// the adapter
TestRepository repo = new TestRepository(this);
Cursor c = repo.getCursor();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_item, c, new String[]{"Nome", "ValorAtual"}, new int[] {R.id.tvNome, R.id.tvValorTotal});
lvPoupancas.setAdapter(adapter);
// ...
}
編輯:
的saving.xml文件:
<?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" >
<ListView
android:id="@+id/lvPoupancas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
希望有人能幫助我。
感謝和抱歉我的英語不好。
只是爲了解釋:當這段代碼運行時,沒有任何反應。 – fvss 2012-02-04 00:54:43
有趣的部分是'lvPoupancas'的聲明。 – user802421 2012-02-04 01:15:41
對不起,我現在把xml文件。 – fvss 2012-02-04 01:32:59