2011-03-02 83 views
-1

可能重複:
How to print the data which is coming from the edittext?如何將EditText內容打印到日誌中?

final ViewGroup layout6 = (ViewGroup) LayoutInflater.from(Menus.this) 
    .inflate(R.layout.beefkabobsandwhichdialog, null); 

AlertDialog.Builder builder6 = new AlertDialog.Builder(Menus.this); 
builder6.setView(
    LayoutInflater.from(Menus.this) 
     .inflate(R.layout.beefkabobsandwhichdialog, null)); 
builder6.setPositiveButton("Add2Order",new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
     String str = ((EditText)layout6.findViewById(R.id.quantityedittext1)) 
      .getText().toString(); 
     System.out.println(str); 
    } 
}); 
+0

爲什麼再次問候。你剛剛問過這個問題,不是嗎?有一個downvote和一個美好的一天。 – Klaus 2011-03-02 13:33:40

+1

但我無法在logcat中打印str值... y? – sam 2011-03-02 13:37:47

+1

重複:http://stackoverflow.com/questions/5167703/how-to-print-the-data-which-is-coming-from-the-edittext – HaskellElephant 2011-03-02 13:44:38

回答

1

你所寫的內容將有打印出來的結果在logcat的但是這將是很難看到的。有兩兩件事你可以嘗試:

更換

System.out.println(str); 

System.out.println("****************************************************"); 
System.out.println(str);  
System.out.println("****************************************************"); 

這將是很難錯過。

雖然人們通常會做的是以Logcat格式打印出來。這裏是代碼如何做到這一點:

Log.i(tag, str); 

'標記'這裏是一個字符串,它會顯示在Logcat的左側列。這樣可以非常容易地識別,因爲您可以添加過濾器,只顯示所選標籤的日誌。這是推薦的方式,但您可以使用標準的System.out.println()。它確實有用,只是很難看到。

+0

請使用log.i(tag,str);格式爲任何Android項目。這是標準,長遠來說會讓你的生活更輕鬆。 – FuegoFingers 2011-03-02 13:55:19

+0

我不明白,這是針對我還是rajesh? – NotACleverMan 2011-03-02 14:01:10