【问题标题】:Where I will declare ListView我将在哪里声明 ListView
【发布时间】:2015-09-28 22:58:39
【问题描述】:

我是初学者,所以请任何人帮助我,我将在哪里声明 ListView 布局。
错误是:您的内容必须有一个 id 属性为 'android.R.id.list 的 ListView。

以下是主要活动代码:

    public class Check extends ListActivity {
    TextView selection;
    public int idToModify;
    DataManipulator dm;
    List<String[]> list = new ArrayList<String[]>();
    List<String[]> names2 = null;
    String[] stg1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check);     
        dm = new DataManipulator(this);
        names2 = dm.selectAll();
        stg1 = new String[names2.size()];
        int x=0;
        String stg;

        for(String[] name : names2)
        {
            stg = name[1]+ ","+name[2]+ "," +name[3]+ "," +name[4];
            stg1[x] = stg;
            x++;
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,stg1);
        this.setListAdapter(adapter);
        selection = (TextView)findViewById(R.id.listTextView);
    }

    public void onListItemClick(ListView parent, View v, int position, long id)
    {
        selection.setText(stg1[position]);  
    }
}

下面是 ListView 布局代码:

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

【问题讨论】:

标签: java android


【解决方案1】:

您使用的是内置 ListView,因此您的 xml 文件在提及 ID 时必须指定关键字 android。

像这样重命名 ListView 的 id,

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

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多