安卓:项文本ListView中不显示 [英] Android: Item Text not showing in listView
问题描述
我已经努力了很久,我想我已经到位code,但由于该项目不被添加到ListView什么是错的。遵循我code:
I've been trying for a long time, and I think I have the code in place, but something is wrong because the item is not being added to the listView. Follows my code:
public class EditDoctors extends Activity implements OnClickListener {
SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
ListView editDoc;
int[] to;
String[] from;
EditText addDoc, docPos;
String row1, row2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editdoc);
addDoc = (EditText) findViewById(R.id.newDoc);
docPos = (EditText)findViewById(R.id.docPos);
editDoc = (ListView) findViewById(R.id.editDoc);
TextView textview = new TextView(this);
textview.setText("This is the Songs tab");
Button adddocs = (Button)findViewById(R.id.addbutton);
adddocs.setOnClickListener(this);
from = new String[] { "row_1", "row_2" };
to = new int[] { R.id.row1, R.id.row2 };
adapter = new Adapter(this, painItems, R.layout.mylistlayout,from, to);
editDoc.setAdapter(adapter);
}
public class Adapter extends SimpleAdapter {
HashMap<String, String> map = new HashMap<String, String>();
View row;
public Adapter(Context context,
List<? extends Map<String, String>> data, int resource,
String[] from, int[] to) {
super(context, data, resource, from, to);
}
}
private void addItem() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("row_1", row1);
map.put("row_2", row2);
painItems.add(map);
adapter.notifyDataSetChanged();
}
@Override
public void onClick(View arg0) {
row1 = addDoc.getText().toString();
Toast.makeText(this, row1, Toast.LENGTH_SHORT).show();
row2 = docPos.getText().toString();
adapter.notifyDataSetChanged();
addItem();
}
}
这应该创建一个2成荫的listItem,但它并没有,线条空(无文本)。敬酒你看到OnClickMethod返回文本就好了,但我想补充的项目有什么也没有。先谢谢了。
This should create a 2-lined listItem, but it doesn't, the lines are empty(no text). The Toast you see in the OnClickMethod returns the text just fine, but the item I add has nothing in it. Thanks in advance.
推荐答案
我是用从书的数据绑定的例子的你好的Android 的埃德伯内特(伟大的书)。
I was using the Data Binding example from the book Hello Android by Ed Burnette (great book).
我改变了从A到RelativeLayout的一个的LinearLayout的项目布局;但是,当我做了改变我没加的方向。
I changed the item layout from A RelativeLayout to a LinearLayout; however, I did not add an orientation when I made the change.
在我添加的安卓方向=垂直一切正常
在这一个两个小时我的生活。
Two hours of my life on this one.
这篇关于安卓:项文本ListView中不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!