如果使用

m_currDlg = new AlertDialog.Builder(m_activity).create();

m_currDlg.setView(textEntryView,0,0,0,0);

m_currDlg.show();

则可以得到想要的自定义的dialog

此时就可以控制Dialog在按了OK或者cancel的显示还是消失了

LayoutInflater factory = LayoutInflater.from(m_activity);

final View textEntryView = factory.inflate(R.layout.dialog_edit_text, null);

EditText etCon = (EditText)textEntryView.findViewById(R.id.edittext_edit);

etCon.setText(strContent);

TextView tvCon = (TextView)textEntryView.findViewById(R.id.edittext_view);

m_btnConfirm = (Button)textEntryView.findViewById(R.id.plsBtnConfirm);

m_btnCancel = (Button)textEntryView.findViewById(R.id.plsBtnCancel);

if (0 != strTitle.length())

tvCon.setText(strTitle);

m_currDlg = new AlertDialog.Builder(m_activity).create();

m_currDlg.setView(textEntryView);

m_currDlg.show();

View.OnClickListener clickListener = new View.OnClickListener(){

@Override

public void onClick(View v) {

long id = v.getId();

if(id == R.id.plsBtnConfirm){

EditText etPl = (EditText)textEntryView.findViewById(R.id.edittext_edit);

String str = etPl.getText().toString().trim();

boolean bValid = UtilFun.isInputTextValid(str);

if (!bValid)

{

showWarningDlg("",m_activity.getString(R.string.str_invalid_playlist));

}

else

{

boolean bDismiss = isPlaylistNameValid(str,NEWPLS_INPUT);

if(bDismiss == true) m_currDlg.cancel();

}

}else if(id ==R.id.plsBtnCancel){

m_currDlg.cancel();

}

}

};

m_btnConfirm.setOnClickListener(clickListener);

m_btnCancel.setOnClickListener(clickListener);

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐