Android 台灣中文網

標題: 要怎麼抓取LayoutInflater內的edittext的值呢 [打印本頁]

作者: wind8894    時間: 2013-1-3 20:35
標題: 要怎麼抓取LayoutInflater內的edittext的值呢
當我按下button時,會彈出一個包含edittext的視窗,可以輸入

那我要怎麼抓取這個edittext的值呢?
java
  1. /*LayoutInflater inflater = LayoutInflater.from(listview.this);
  2.                 View newfolder_view = inflater.inflate(R.layout.newfolder,null);
  3.                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
  4.                 builder.setTitle(R.string.create_new_folder);               
  5.                 builder.setView(newfolder_view);
  6.                 builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
  7.                                
  8.                                 public void onClick(DialogInterface dialog, int which) {
  9.                                         //確定按鈕事件
  10.                                         setResult(RESULT_OK);
  11. //                                        dialog.dismiss();
  12.                                        
  13.                                 }
  14.                         })
  15.                         .setNegativeButton("取消", new DialogInterface.OnClickListener() {
  16.                                
  17.                                 public void onClick(DialogInterface dialog, int which) {
  18.                                         //取消按鈕事件
  19. //                                        dialog.dismiss();
  20.                                 }
  21.                         });
  22.                 final AlertDialog dialog = builder.create();
  23.                 dialog.show();*/
複製代碼
xml

  1.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.         android:id="@+id/linearLayout1"
  3.         android:layout_width="fill_parent"
  4.         android:layout_height="fill_parent"
  5.         android:orientation="horizontal" >

  6.         <ImageView
  7.             android:id="@+id/imageView1"
  8.             android:layout_width="wrap_content"
  9.             android:layout_height="wrap_content"
  10.             android:layout_marginLeft="10dp"
  11.             android:src="@drawable/folder_sd" />

  12.         <EditText
  13.             android:id="@+id/foldername"
  14.             android:layout_width="fill_parent"
  15.             android:layout_height="wrap_content"
  16.             android:layout_marginTop="5dp"
  17.             android:layout_marginLeft="10dp"
  18.              >

  19.             <requestFocus />
  20.         </EditText>

  21.     </LinearLayout>
複製代碼
2013-01-03_20-28-29.png
登錄/註冊後可看大圖