查找Android XML标记

时间:2016-07-06 11:51:20

标签: android xml

我目前正在尝试修复错误“您的内容必须有一个ListView,其id属性为'android.R.list'。

我在Stack Exchange上找到了以下问题的答案:

Your content must have a ListView whose id attribute is 'android.R.id.list'

我已经应用了解决方案,但后来我想问这个问题:

“那我如何引用android定义的XML标签?

然而,由于声誉系统,我无法评论这个小问题。我为此道歉,但有人可以回答这个问题吗?

提前谢谢。

有关您的信息,这是我的列表视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>
</LinearLayout>

这就是我想要传递的内容:

   lv = (ListView) convertView.findViewById(R.id.ExceedingList);

这就是我得到的错误:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.denny.phonebelt/com.example.denny.phonebelt.SettingsMenu}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

如果由于某种原因问题是由另一个错误引起的,我会在这里给出实际的代码:

    final Button ExceedingLimitButton = (Button)findViewById(R.id.ExceedingLimitButton);
    ExceedingLimitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final AlertDialog.Builder ExceedingLimitDialog = new AlertDialog.Builder(SettingsMenu.this);
            //Setting ListView
            LayoutInflater inflater = getLayoutInflater();
            View convertView = inflater.inflate(R.layout.exceeding_dialog, null);
            lv = (ListView) convertView.findViewById(android.R.id.list);
            ArrayAdapter<String> adapter = new ArrayAdapter<>(SettingsMenu.this, android.R.layout.simple_list_item_single_choice, ExceedingSelection);
            lv.setAdapter(adapter);
            lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    int SelectedItem = Integer.parseInt(ExceedingSelection[position]);
                    PhoneBelt.setExceedInt(SelectedItem);
                    String Selection = getString(R.string.Selection);
                    String message = (Selection + SelectedItem);
                    Toast toast = Toast.makeText(SettingsMenu.this, message, Toast.LENGTH_LONG);
                    toast.show();
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    Toast toast = Toast.makeText(SettingsMenu.this, "You have not selected anything", Toast.LENGTH_SHORT);
                    toast.show();
                }
            });
            ExceedingLimitDialog.setView(convertView);
            ExceedingLimitDialog.setTitle(R.string.Exceeding_Limit_Title);
            ExceedingLimitDialog.setMessage(R.string.Exceeding_Limit_Message);
            ExceedingLimitDialog.setCancelable(true);
            AlertDialog alert = ExceedingLimitDialog.create();
            alert.show();
        }
    });

3 个答案:

答案 0 :(得分:2)

而不是:

android:id="@android:id/list"

写:

 android:id="@+id/list"

您必须声明一个新ID并用它标记列表。

答案 1 :(得分:0)

使用此:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>
</LinearLayout>

答案 2 :(得分:0)

您对java代码的引用是>>> [{i[0] : list(i[1:])} for i in list_of_tuples] [{'company_name': [56, 'green']}, {'other_company': [43, 'blue']}] 。但在xml中是ExceedingList。你也应该创建新的id。

所以,

list

如果您使用 android:id="@+id/ExceedingList" 表示您尝试引用已创建的ID(android:id="@android:id/ExceedingList"

然后致电,

ExceedingList

这可能有助于你