java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list“ [英] java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

查看:125
本文介绍了java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,一直存在simialr问题,但我不能让虽然我看那些它甚至工作。该错误信息是:java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是android.R.id.list。我曾试图改变ID列出。在另一回事。这是什么code是这样的:

  

公共类committeeFragment扩展SherlockListFragment {

     

私人CommitteeAdapter适配器;公共无效   onActivityCreated(捆绑savedInstanceState){         super.onActivityCreated(savedInstanceState);适配器=新   CommitteeAdapter(getActivity()getApplicationContext());         setListAdapter(适配器); }

     

公开查看onCreateView(LayoutInflater充气,的ViewGroup   容器,包savedInstanceState){         super.onCreate(savedInstanceState);返回   inflater.inflate(R.layout.fragment_committee,集装箱,假); }           公共无效   refreshList(){adapter.updateDataSet();         adapter.notifyDataSetChanged(); }}

它使用以下适配器:

  

公共类CommitteeAdapter扩展了BaseAdapter {私人   ArrayList的committeeList;私人上下文的背景下;

     

公共CommitteeAdapter(上下文的背景下){this.context =环境;         CommitteeDatabaseAdapter dbAdapter =新   CommitteeDatabaseAdapter(上下文); committeeList =   dbAdapter.readAllCommittees(); }公共无效updateDataSet(){         CommitteeDatabaseAdapter dbAdapter =新   CommitteeDatabaseAdapter(上下文); committeeList =   dbAdapter.readAllCommittees(); }

     

@覆盖公共视图getView(INT位置,查看convertView,   ViewGroup中父){LayoutInflater VI =(LayoutInflater)   context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

  StudentCommittee委员会= committeeList.get(位置);

  视图V = vi.inflate(R.layout.list_item_committee,NULL);的TextView
 

     

sectionName =(TextView中)v.findViewById(R.id.committee_namn);

  sectionName.setText(committee.getName());返回伏; }
 

     

@覆盖公众诠释getCount将(){返​​回committeeList.size(); }

     

@覆盖公共StudentCommittee的getItem(INT位置){返回   committeeList.get(位置); }

     

@覆盖公共长getItemId(INT位置){返回位置;     }}

下面是XML文件,指定列表(fragment_committee):

  

 <的TextView
    风格=@风格/ AppsolutText.Headline
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=Festerier/>

 <查看
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =2DP
    机器人:背景=@可绘制/ divider_sliding_menu_item/>

<的ListView
    机器人:ID =@ + ID /列表
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT/>

<的TextView
    风格=@风格/ AppsolutText.Normal
    机器人:ID =@机器人:ID /空
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:文本=UppdateraFÖRATT本身连接LISTA超过festerier OCH fadderierKräverinternetanslutning。/>
 

     

下面是XML列表项:

  

 < ImageView的
    机器人:ID =@ + ID / committee_symbol
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =0
    机器人:paddingBottom会=10dp
    机器人:paddingRight =10dp
    机器人:paddingTop =10dp/>

<的TextView
    机器人:ID =@ + ID / committee_namn
    风格=@风格/ AppsolutText.ListHeader
    机器人:layout_width =0dp
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =1/>
 

     

我希望你能弄清楚什么是错的。我还有一个列表视图已在另一个XML文件whithin项目相同的ID(清单)。我不知道这是一个问题。请帮我解决这个问题。

解决方案

该问题是在这里:

 机器人:ID =@ + ID /列表
 

要添加一个新的ID为您的ListView但ListFragment需要一个默认的Andr​​oid ListView控件ID为

改变你的ListView编号为:

 <的ListView
   机器人:ID =@ ID / Android的:清单
   机器人:layout_width =match_parent
   机器人:layout_height =WRAP_CONTENT/>
 

I know that there has been simialr questions but I can't make it work even though I look at those. The error message is: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'. I have tried to change the id to list. In another. This what the code looks like:

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(); } }

It's using the following adapter:

public class CommitteeAdapter extends BaseAdapter{ private ArrayList 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; } }

Here is the xml-file that specifies the list(fragment_committee):

<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."/>

Here is the xml for the list item:

<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" />

I hope that you can figure out what's wrong. I have another listview that has the same id (list) in another xml-file whithin the project. I don't know if that's a problem. Please help me solve the problem.

解决方案

The problem is here :

android:id="@+id/list"

you are adding a new id for your ListView but ListFragment needs a default Android ListView Id

change your ListView Id to :

<ListView
   android:id="@id/android:list"
   android:layout_width="match_parent"
   android:layout_height="wrap_content" />

这篇关于java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆