2014-04-06 27 views
0

我想將textview的數據添加到數組中。 myLogClass是一個數組列表和這些代碼如下:從textview的數組列表中添加數據

String txt_datetime = txt_date.getText().toString();; 
    String txt_messageData = txt_message.getText().toString(); 
    String txt_day = this.dayName; 



    List<myLogClass> results = null; 
    results = new ArrayList<myLogClass>(); 

    results.add(new myLogClass(txt_datetime, txt_messageData, txt_day)); 

我有setter和在myLogClass getter方法和具有3可變構造函數如下:

public diaryLogs(int dateTime, String messagetxt, String dayN){ 

    setDayCode(dateTime); 
    setDateTime(messagetxt); 
    setDairyText(dayN); 

}//end constructor. 

雖然我試圖添加方法,它說構造函數是未定義的。

感謝您的幫助提前

+0

問題是......? – Blackbelt

+0

已編輯的問題,請看看謝謝@blackbelt – usrNotFound

+0

您將'txt_datetime'定義爲'string',但在構造函數中它是'int',將'txt_datetime'轉換爲'int' http://stackoverflow.com/questions/5585779/how-to-convert-string-to-int-in- – Mobi

回答

0

爲了能夠將diaryLogs實例添加到結果數組,該ArrayList應該是diaryLogs。這裏我在做另一個問題之前做了修改。

diaryLogs構造函數的定義是(int dateTime, String messagetxt, String dayN),也就是說,函數需要一個int,然後是兩個字符串作爲參數。

爲了得到這個工作,你需要將字符串txt_datetime轉換爲int,然後將它傳遞給構造函數。

String txt_datetime = txt_date.getText().toString();; 
String txt_messageData = txt_message.getText().toString(); 
String txt_day = this.dayName; 

// Convert to Integer 
int txt_datetime_int = Integer.parseInt(txt_datetime); 

// Define the ArrayList as diaryLogs 
List<diaryLogs> results = null; 
results = new ArrayList<diaryLogs>(); 

// Pass as Integer 
results.add(new diaryLogs(txt_datetime_int , txt_messageData, txt_day) 
+0

乾杯兄弟!感謝您的幫助表示感謝 – usrNotFound

0

在這一行:

results.add(new diaryLogs(txt_datetime, txt_messageData, txt_day)); 

txt_datetime是一個字符串,而整數預期。這就是爲什麼你會收到這條消息。