android:layout_width="0.0dip",《转载》Android AlertDialog 方法setView(view,0,0,0,0)的使用

本文转载>>About Doyee ®™<

dialog_edit_text.xml如下:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="wrap_content">

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:text="@string/str_info_na"

android:layout_marginTop="8dip"

android:layout_marginBottom="8dip"

android:layout_marginLeft="8dip"

android:layout_marginRight="8dip">

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:singleLine="true"

android:layout_marginBottom="8dip"

android:layout_marginLeft="8dip"

android:layout_marginRight="8dip">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding ="6px"

android:background="#ffffff">

android:layout_width="120px" android:layout_height="wrap_content"

android:text="@string/str_ok"

android:layout_alignParentLeft="true" />

android:layout_width="120px" android:layout_height="wrap_content"

android:text="@string/str_cancel"

android:layout_alignParentRight="true" />

通常使用的SetView(view)会显示如下效果

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();

底部有条黑线

如果使用

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值