有人可以告诉我如何在不使用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