綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 要怎麼抓取LayoutInflater內的edittext的值呢

[複製連結] 查看: 1912|回覆: 1|好評: 0
跳轉到指定樓層
樓主
wind8894 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2013-1-3 20:35

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
當我按下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>
複製代碼
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
 樓主| wind8894 | 收聽TA | 只看該作者
發表於 2013-1-3 23:57
沒人回答

剛好自己找到答案了

附上程式碼
  1. Builder dialog = new AlertDialog.Builder(this);
  2.                 LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  3.                 LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.newfolder, null);
  4.                 dialog.setView(layout);
  5.                 get_foldername = (EditText)layout.findViewById(R.id.foldername);
  6.                 dialog.setTitle(R.string.create_new_folder);
  7.                 dialog.setPositiveButton("新增", new DialogInterface.OnClickListener() {
  8.                     public void onClick(DialogInterface dialog, int which) {
  9.                             getfolder_name = get_foldername.getText().toString();
  10.                             pd = ProgressDialog.show(listview_b.this, "新增資料夾", "建立中......");                                         
  11.                                     new Thread(addfolderRun).start();  //新增資料夾執行緒
  12.                     }
  13.                 });
  14.                  
  15.                 dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
  16.                     public void onClick(DialogInterface dialog, int which) {
  17.                         
  18.                     }
  19.                 });
  20.                 dialog.show();
複製代碼

評分

參與人數 1幫助 +1 收起 理由
qb425425 + 1

查看全部評分

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則