ListView 始终为空
嘿!
我的 ListView
在我的代码中始终为 null。我没有计划为什么。错误发生在setAdapter方法请帮助
代码:
ListView lv = (ListView)findViewById(R.id.lv_sp);
ArrayList<SPEntry> list = new ArrayList<SPEntry> ();
EntryParse ep = new EntryParse(LVEntries.this, getIntent().getExtras().getString("JSON"));
list = ep.getList();
//list= new ArrayList<SPEntry>();
Log.e("SP",String.valueOf(list.size()));
ca = new CustomAdapter(this, R.layout.customlistitem, list);
lv.setAdapter(ca);
ca.notifyDataSetChanged();
布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/lv_sp" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" ></ListView>
</LinearLayout>
Hy!
My ListView
is always null in my code. I don't have a plan why. The Error occurs in the setAdapter Method please help
Code:
ListView lv = (ListView)findViewById(R.id.lv_sp);
ArrayList<SPEntry> list = new ArrayList<SPEntry> ();
EntryParse ep = new EntryParse(LVEntries.this, getIntent().getExtras().getString("JSON"));
list = ep.getList();
//list= new ArrayList<SPEntry>();
Log.e("SP",String.valueOf(list.size()));
ca = new CustomAdapter(this, R.layout.customlistitem, list);
lv.setAdapter(ca);
ca.notifyDataSetChanged();
Layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/lv_sp" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" ></ListView>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到对
setContentView
的调用。您必须首先设置布局,然后检索视图。I don't see a call to
setContentView
. You must set the layout first, then retrieve views.