大家好,欢迎来到IT知识分享网。
public class MyActivity extends Activity {
//创建按钮启动弹窗的按钮
private Button mbutton,mbutton1;
private Button mbutton,mbutton1;
//PopWindow弹窗内容
private String[] array=new String[]{“张三”,”李四”,”王二”,”麻子”};
private String[] array=new String[]{“张三”,”李四”,”王二”,”麻子”};
//创建PopWindow变量
private PopupWindow popupWindow;
private PopupWindow popupWindow;
//创建Dialog变量
AlertDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//找到Dialog启动按钮并监听
mbutton=(Button)findViewById(R.id.button);
mbutton=(Button)findViewById(R.id.button);
mbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@Override
public void onClick(View view) {
//弹出这个对话框
showDialog(1);
}
});
showDialog(1);
}
});
//将当前对象转成 LayoutInflater对象
LayoutInflater layoutInflater=LayoutInflater.from(this);
LayoutInflater layoutInflater=LayoutInflater.from(this);
//找到 PopWindow布局XML转成View对象
View v=layoutInflater.inflate(R.layout.popwindow_item_list,null);
View v=layoutInflater.inflate(R.layout.popwindow_item_list,null);
//用ListView对象接收XML文件中的ListView
ListView listView=(ListView)v.findViewById(R.id.onetextview);
ListView listView=(ListView)v.findViewById(R.id.onetextview);
//因为只有字符,使用ArrayAdapter放入array数组的值
ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,array);
ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,array);
//为这个listView放入这个适配器
listView.setAdapter(arrayAdapter);
listView.setAdapter(arrayAdapter);
//找到启动PopWindow的启动按钮并监听
mbutton1=(Button)findViewById(R.id.button1);
mbutton1=(Button)findViewById(R.id.button1);
//new一个PopWindow并放入v初iew值和始化弹窗大小
popupWindow=new PopupWindow(v,200,400);
mbutton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (popupWindow.isShowing()){
popupWindow.dismiss();
}else {
popupWindow.showAsDropDown(mbutton1);
}
}
});
}
protected Dialog onCreateDialog(int id) {
popupWindow=new PopupWindow(v,200,400);
mbutton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (popupWindow.isShowing()){
popupWindow.dismiss();
}else {
popupWindow.showAsDropDown(mbutton1);
}
}
});
}
protected Dialog onCreateDialog(int id) {
//判断ID
switch (id){
switch (id){
//当id是0的时候弹出这个
case 0:AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(“aa”);
builder.setMessage(“bb”);
dialog=builder.create();
return dialog;
case 0:AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(“aa”);
builder.setMessage(“bb”);
dialog=builder.create();
return dialog;
//当id是1弹出这个
case 1:MyDialog dialog1=new MyDialog(MyActivity.this);
return dialog1;
}
return null;
}
}
case 1:MyDialog dialog1=new MyDialog(MyActivity.this);
return dialog1;
}
return null;
}
}
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/149188.html