第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

findviewbyid在對話框中返回null

findviewbyid在對話框中返回null

猛跑小豬 2019-11-03 08:04:09
我有一個自定義對話框,當我嘗試獲取EditText的值時,它返回null。該行返回nullEditText et = (EditText)findViewById(R.id.username_edit);這是完整的代碼。protected Dialog onCreateDialog(int id) {    switch (id) {    case DIALOG_TEXT_ENTRY:        LayoutInflater factory = LayoutInflater.from(this);        final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);        return new AlertDialog.Builder(TicTacToe.this)            //.setIconAttribute(android.R.attr.alertDialogIcon)            .setTitle(getTitleText())            .setView(textEntryView)            .setPositiveButton("JOIN GAME", new DialogInterface.OnClickListener() {                public void onClick(DialogInterface dialog, int whichButton) {                    try                    {                        EditText et = (EditText)findViewById(R.id.username_edit);                            playerName = et.getText().toString();                    }                    catch (Exception e)                    {                    }                }            })            .create();    }    return null;}
查看完整描述

3 回答

?
慕碼人2483693

TA貢獻1860條經(jīng)驗 獲得超9個贊

嘗試這個:


EditText et = (EditText)textEntryView.findViewById(R.id.username_edit);

您必須告訴在哪個視圖中找到ID。否則,它將嘗試通過xml布局setContentView(通常在中聲明onCreate)夸大視圖中的ID。


查看完整回答
反對 回復 2019-11-04
  • 3 回答
  • 0 關注
  • 292 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號