【发布时间】: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 的新手)
【问题讨论】: