2012-09-25 58 views
0

我有這樣的代碼:如何將字符串添加到嵌套的Arraylist?

ArrayList<ArrayList<String>> row = new ArrayList<ArrayList<String>>(); 
ArrayList<String> column = new ArrayList<String>(); 

我的問題是我不能字符串添加到它。 如何從TextView(Android中)添加字符串?

+1

你想添加字符串列或行? – VendettaDroid

回答

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); 
+0

非常感謝你! :) – Soysauce

3

假設你已經宣佈你TextView XML(可與您的TextView的id替換myTextView):

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); 
} 
+0

非常感謝你@phil。 – Soysauce