Android调用自定义Dialog中的控件
16lz
2022-04-18
public class PopUpDialog extends Dialog {
Context context;
private View customView;
public PopUpDialog(Context context) {
super(context);
this.context = context;
// TODO Auto-generated constructor stub
}
public PopUpDialog(Context context, int theme){
super(context, theme);
this.context = context;
LayoutInflater inflater= LayoutInflater.from(context);
customView = inflater.inflate(R.layout.mydialog, null);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(customView);
}
@Override
public View findViewById(int id) {
// TODO Auto-generated method stub
return super.findViewById(id);
}
public View getCustomView() {
return customView;
}
Context context;
private View customView;
public PopUpDialog(Context context) {
super(context);
this.context = context;
// TODO Auto-generated constructor stub
}
public PopUpDialog(Context context, int theme){
super(context, theme);
this.context = context;
LayoutInflater inflater= LayoutInflater.from(context);
customView = inflater.inflate(R.layout.mydialog, null);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(customView);
}
@Override
public View findViewById(int id) {
// TODO Auto-generated method stub
return super.findViewById(id);
}
public View getCustomView() {
return customView;
}
}
customView = inflater.inflate(R.layout.mydialog, null);通过此语句获取view“指针”(借用C的术语),在新的Activity中实现调用自定义对话框中的控件。
顺便说一句,csdn的代码插入对浏览器支持真烂。
PopUpDialog newDialog = new PopUpDialog(MsgReView.this, R.style.MyDialog);
newDialog.setCanceledOnTouchOutside(true);
View view = newDialog.getCustomView();
TextView text1 = (TextView)view.findViewById(R.id.textViewTotal);
text1.setText("调查人数:5");
更多相关文章
- android EditText控件
- Android(安卓)中沉浸式状态栏实现
- Android文字跑马灯控件(文本自动水平滚动)
- android 动态设置控件大小
- Android(安卓)解决Handler在运行时加载报空指针异常
- Android复习(九)
- android事件分发机制一
- android : 背景透明的 Dialog
- lyricView--歌词显示控件