【问题标题】:What does these three lines of codes mean?这三行代码是什么意思?
【发布时间】:2019-11-09 06:32:40
【问题描述】:

我很难理解某些代码行。使用Array Adapter 时,这三行是什么意思?

WordAdapter itemsAdapter = new WordAdapter(this,words);
ListView listView = findViewById(R.id.numlist);
listView.setAdapter(itemsAdapter);

【问题讨论】:

    标签: java android android-listview android-arrayadapter


    【解决方案1】:
    1. WordAdapter itemsAdapter = new WordAdapter(this,words);

      一个自定义适配器类,用于添加您的 listArray(包含将添加到列表视图的数据)、绑定视图持有者类和其余的东西,这些东西将为您在列表视图中显示数据提供自定义。

    2. ListView listView = findViewById(R.id.numlist);

      ListView 是android sdk 中预定义的组件类,使用该类您将创建对xml 声明组件的对象引用,即.. R.id.numlist 到您的java 类文件中。

    3. listView.setAdapter(itemsAdapter);

      此行将适配器附加到列表视图,以便列表数组中的数据将显示在列表视图上

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多