【问题标题】:Populating a ListView using FrameLayouts使用 FrameLayouts 填充 ListView
【发布时间】:2016-04-16 13:37:26
【问题描述】:

我目前正在学习 Udacity android 开发免费课程,但我对一个应用程序有了一个想法,并想尝试一些我刚刚学到的东西。

我的问题如下;我试图用一些 FrameLayouts 制作一个 ListView。我正在使用这个 FrameLayouts,因为我不想创建字符串列表,而是我刚刚制作的“盒子”列表。我尝试使用使用 frameLayouts 的 ArrayAdapter 模板,但编译器说我需要使用 TextView。我可以在这里做什么?

最后的想法是得到一些引擎,就像这个页面中显示的引擎一样。 promedioponderado.herokuapp.com

【问题讨论】:

  • 问题是什么?

标签: java android listview android-studio


【解决方案1】:

假设你有一个想要显示的类型,可以这样说:

class Foo{
    final int bar;
    Foo(int bar){this.bar = bar;}
}

您可以覆盖适配器的View getView(int position, View convertView, ViewGroup parent) 方法并执行类似的操作

LayoutInflater inflater = (LayoutInflater) context
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view= inflater.inflate(R.layout.your_frame_layout_thingy, parent, false);

EditText box= (EditText) view.findViewById(R.id.my_box);
box.setText("Value is" + getItem(position).bar);

记得回view

有关更多详细信息,我建议您查看Adapters 的工作原理,this 之类的东西似乎是一个不错的起点。

如果您不了解 class Foo 的全部内容,我建议您研究 Java 基础知识,因为在对 Java 没有一些基本了解的情况下开始 Android 编程是相当困难的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多