【问题标题】:ListView single Choice adapt to size of itemListView 单项选择适应项目的大小
【发布时间】:2016-09-04 03:15:04
【问题描述】:

我有一个ListView,它只有一个选择。我为它放置了一个添加功能。我的代码是:

public void add(){
    String name = (allergytxt.getText().toString() + "\n" +
                   desctxt.getText().toString() + "\n" +
                   doctxt.getText().toString() + "\n" +
                   notxt.getText().toString());

    if (!name.isEmpty() && name.length() > 0) {
        adapter.add(name);
        adapter.notifyDataSetChanged();
        allergytxt.setText("");
        desctxt.setText("");
        doctxt.setText("");
        notxt.setText("");
        Toast.makeText(MainActivity.this, "added",Toast.LENGTH_SHORT).show();
   }
}

显然列表视图只会显示 2 行文本。嘻嘻。 (顺便说一下,我是 android studio 和 java 的新手)

【问题讨论】:

    标签: java android listview


    【解决方案1】:

    最好的方法是创建一个自定义适配器,让您更好地控制每一行的布局。

    默认情况下,适配器会返回一个简单的 TextView 作为一行。如果您想要一个更复杂的 ListView 布局行,则需要一个自定义适配器。起初似乎是一个乏味的过程,但你会习惯的。 This Tutorial 第一次尝试时真的帮助了我。另请查看at this 答案。编码愉快!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多