android几个常用对话框的弹出
来源:互联网 发布:大数据就业 知乎 编辑:程序博客网 时间:2024/06/06 14:05
public class MainActivity extends Activity implements OnClickListener{
private Button tan_dialog ,singleDialog,mutlDialog,progressDialog ;
String[] strings = {"条目1","条目2","条目3","条目4"} ;
boolean[] booleans = {false , false , false ,false ,false} ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tan_dialog = (Button) findViewById(R.id.tan_dialog) ;
singleDialog = (Button) findViewById(R.id.singleDialog) ;
mutlDialog = (Button) findViewById(R.id.mutlDialog) ;
progressDialog = (Button) findViewById(R.id.progressDialog) ;
tan_dialog.setOnClickListener(this) ;
singleDialog.setOnClickListener(this) ;
mutlDialog.setOnClickListener(this) ;
progressDialog.setOnClickListener(this) ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tan_dialog:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this) ;
alertDialog.setTitle("这是一个弹出对话框")
.setMessage("弹出对话框")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show() ;
break;
case R.id.singleDialog:
new AlertDialog.Builder(MainActivity.this)
.setTitle("单选对话框")
.setSingleChoiceItems(strings, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "你选择的是"+which, Toast.LENGTH_SHORT).show() ;
}
})
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.show() ;
break ;
case R.id.mutlDialog:
new AlertDialog.Builder(MainActivity.this)
.setTitle("多选对话框")
.setMessage("这是一个多选对话框")
.setMultiChoiceItems(strings, booleans, new OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInterface dialog, int which,boolean isChecked) {
Toast.makeText(MainActivity.this,
"对话框被选中了"+strings[which]+isChecked, Toast.LENGTH_SHORT).show() ;
}
})
.show() ;
break ;
case R.id.progressDialog:
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this) ;
progressDialog.setTitle("进度条对话陆昂");
progressDialog.setMessage("正在加载中") ;
progressDialog.setMax(100) ;
progressDialog.show() ;
new Thread(){
public void run() {
for(int i=0 ; i < 100 ; i++){
progressDialog.setProgress(i) ;
try {
Thread.sleep(200) ; // 睡眠20us
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
progressDialog.dismiss() ;
}
}.start() ;
break ;
default:
break;
}
}
}
private Button tan_dialog ,singleDialog,mutlDialog,progressDialog ;
String[] strings = {"条目1","条目2","条目3","条目4"} ;
boolean[] booleans = {false , false , false ,false ,false} ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tan_dialog = (Button) findViewById(R.id.tan_dialog) ;
singleDialog = (Button) findViewById(R.id.singleDialog) ;
mutlDialog = (Button) findViewById(R.id.mutlDialog) ;
progressDialog = (Button) findViewById(R.id.progressDialog) ;
tan_dialog.setOnClickListener(this) ;
singleDialog.setOnClickListener(this) ;
mutlDialog.setOnClickListener(this) ;
progressDialog.setOnClickListener(this) ;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tan_dialog:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this) ;
alertDialog.setTitle("这是一个弹出对话框")
.setMessage("弹出对话框")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.show() ;
break;
case R.id.singleDialog:
new AlertDialog.Builder(MainActivity.this)
.setTitle("单选对话框")
.setSingleChoiceItems(strings, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "你选择的是"+which, Toast.LENGTH_SHORT).show() ;
}
})
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.show() ;
break ;
case R.id.mutlDialog:
new AlertDialog.Builder(MainActivity.this)
.setTitle("多选对话框")
.setMessage("这是一个多选对话框")
.setMultiChoiceItems(strings, booleans, new OnMultiChoiceClickListener(){
@Override
public void onClick(DialogInterface dialog, int which,boolean isChecked) {
Toast.makeText(MainActivity.this,
"对话框被选中了"+strings[which]+isChecked, Toast.LENGTH_SHORT).show() ;
}
})
.show() ;
break ;
case R.id.progressDialog:
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this) ;
progressDialog.setTitle("进度条对话陆昂");
progressDialog.setMessage("正在加载中") ;
progressDialog.setMax(100) ;
progressDialog.show() ;
new Thread(){
public void run() {
for(int i=0 ; i < 100 ; i++){
progressDialog.setProgress(i) ;
try {
Thread.sleep(200) ; // 睡眠20us
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
progressDialog.dismiss() ;
}
}.start() ;
break ;
default:
break;
}
}
}
0 0
- android几个常用对话框的弹出
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 常用的android弹出对话框
- 页面置换算法
- JQuery视频总结
- matlab练习程序 ----- HOG
- 安装VIM中文帮助文档
- MATLAB——rand 与 randn 'twister'、'state'、'seed'
- android几个常用对话框的弹出
- 弄懂AVL树与红黑树
- 使用Fragment作为Item的ViewPager不更新问题.
- 判断点是否在三角形内
- Ubuntu 14.04 为 root 帐号开启 SSH 登录
- UNIX时间戳/日期转换
- JavaSe基础XX24——CSS
- 实现鼠标选定矩形框
- 卡尔曼滤波与粒子滤波比较