java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为’android.R.id.list’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为’android.R.id.list’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3789字,纯文字阅读大概需要6分钟。
内容图文
![java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为’android.R.id.list’](/upload/InfoBanner/zyjiaocheng/707/86acd3b27b074f0a99050ca7529a94b5.jpg)
我知道有一些类似的问题,但即使我看着这些问题,我也无法使它成功.错误消息是:
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is ‘android.R.id.list’
.我试图将id更改为list.在另一个.这就是代码的样子:
public class committeeFragment extends SherlockListFragment {
private CommitteeAdapter adapter;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new CommitteeAdapter(getActivity().getApplicationContext());
setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.fragment_committee, container, false);
}
public void
refreshList() {
adapter.updateDataSet();
adapter.notifyDataSetChanged();
}
}
它使用以下适配器:
public class CommitteeAdapter extends BaseAdapter {
private
ArrayList<StudentCommittee> committeeList;
private Context context;
public CommitteeAdapter(Context context) {
this.context = context;
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
public void updateDataSet() {
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
StudentCommittee committee = committeeList.get(position);
View v = vi.inflate(R.layout.list_item_committee, null);
TextView sectionName = (TextView) v.findViewById(R.id.committee_namn);
sectionName.setText(committee.getName());
return v;
}
@Override
public int getCount() {
return committeeList.size();
}
@Override
public StudentCommittee getItem(int position) {
return committeeList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
这是指定列表的xml文件(fragment_committee):
<?xml version="1.0" encoding="utf-8"?> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:tag="@string/tag_fragment_committee"
android:background="@color/white" >
<TextView
style="@style/AppsolutText.Headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Festerier" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@drawable/divider_sliding_menu_item"/>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
style="@style/AppsolutText.Normal"
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Uppdatera f?r att se en lista ?ver festerier och fadderier. Kr?ver internetanslutning."/>
</LinearLayout>
这是列表项的xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/committee_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
<TextView
android:id="@+id/committee_namn"
style="@style/AppsolutText.ListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
我希望你能弄明白什么是错的.我有另一个listview在项目中的另一个xml文件中具有相同的id(列表).我不知道这是不是一个问题.请帮我解决问题.
解决方法:
问题出在这里:
android:id="@+id/list"
您要为ListView添加新ID,但ListFragment需要默认的Android ListView Id
将ListView ID更改为:
06001
内容总结
以上是互联网集市为您收集整理的java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为’android.R.id.list’全部内容,希望文章能够帮你解决java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为’android.R.id.list’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。