我有这段代码:
ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>();
ArrayList<String> column = new ArrayList<String>();
我的问题是我无法添加String。 如何从TextView(在Android中)添加String?
答案 0 :(得分:3)
假设您已在xml中声明了TextView
(将myTextView
替换为TextView的ID):
TextView tv = (TextView) findViewById(R.id.myTextView);
int index = 0;//change to index in row that you want to modify
String text = tv.getText().toString();
ArrayList<String> col = row.get(index);
if (col == null) {
col = new ArrayList<String>();
col.add(text);
row.add(col);
}
else {
col.add(text);
}
答案 1 :(得分:1)
ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>();
ArrayList<String> column = new ArrayList<String>();
row.add(column);
column.add(myString);
String theString = row.get(0).get(0);