[問題] 在繼承的Class中抓CustomView的element

看板AndroidDev作者 (HyDroGen2528)時間11年前 (2014/05/15 01:06), 11年前編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
大家好,我的Android觀念可能沒有很正確,還請大家幫忙 .. 目前有寫一個APP,裡面選單點選之後會以AlertDialog的樣子顯示 而且每一個Dialog都是自定義的Layout,每個XML都是沒有關聯的 之後因為有考慮到跨版本的問題,想把一些實作的部份拉出來放到另外一個Class中 這樣以後再開發上或維護上也相對方便 而我遇到的問題是 目前所有AlertDialog出現的code都是寫在OnClickListener中 大概是長下面這樣,一些沒相關的就拿掉了 LayoutInflater inflater = LayoutInflater.from(context) ; View customView = inflater.inflate(R.layout.menu_systemcondition,null) ; View customTitle = inflater.inflate(R.layout.custom_title,null) ; AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setView(customView) ; dialog.setCustomTitle(customTitle) ; Title = (TextView)customTitle.findViewById(R.id.custom_title_dialogName) ; Icon = (ImageView)customTitle.findViewById(R.id.custom_dialog_title_icon) ; Title.setText(R.string.String_List_Name_1); Icon.setImageResource(R.drawable.system); 而我在另外一個Class中有繼承MainActivity 這個Class暫且就先稱作Implement 我在MainActivity宣告一個Implement func = new Implement (Activity) ; 然後在Implement的Constructor中接Activity 可是我用Activity.findViewById 找到的並不是alertdialog中的而是MainActivity的物件 試了好久都是找到Main的 QQ 請問有人知道該怎麼在繼承的Class中findViewById找到指定Layout的物件嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.115.90.129 ※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1400087194.A.C21.html ※ 編輯: HyDroGen2528 (59.115.90.129), 05/15/2014 01:07:45

05/15 10:07, , 1F
Activity.getDialog.findViewById 試試 要自己寫getDialog
05/15 10:07, 1F
謝謝 請問getDialog就直接把Dialog傳過去嗎 ? ※ 編輯: HyDroGen2528 (59.115.90.129), 05/15/2014 12:31:01

05/15 12:50, , 2F
是的
05/15 12:50, 2F
好的 那我在試試看 謝謝你的回應 ^____^ ※ 編輯: HyDroGen2528 (140.138.17.135), 05/15/2014 13:14:14
文章代碼(AID): #1JSwAQmX (AndroidDev)