android自定义对话框工具类
来源:互联网 发布:淘宝干货 编辑:程序博客网 时间:2024/06/04 17:52
public class CustomDialog {private AlertDialog.Builder builder;private Context context;public CustomDialog(Context context) {// TODO Auto-generated constructor stubthis.context = context;}public void createDialog(String buttontext, String title, String message,final CallBack callBack) {builder = new AlertDialog.Builder(context);builder.setTitle(title);builder.setMessage(message);builder.setPositiveButton(buttontext, new OnClickListener() {@Overridepublic void onClick(DialogInterface arg0, int arg1) {// TODO Auto-generated method stubcallBack.isConfirm(true);}});builder.create().show();}public interface CallBack {public void isConfirm(boolean flag);}public void createToasts(String message,LayoutInflater layoutInflater) {// Toast.makeText(context, message, Toast.LENGTH_LONG).show(); View view = layoutInflater.inflate(R.layout.toast, null); TextView textView = (TextView)view.findViewById(R.id.text); textView.setText(message); Toast toast = new Toast(context); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(view); toast.show();}}
public class MainActivity extends Activity {private Button button;private Button button2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button = (Button) this.findViewById(R.id.button1);button2 = (Button) this.findViewById(R.id.button2);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubCustomDialog dialog = new CustomDialog(MainActivity.this);dialog.createDialog("确定", "提示", "您确定要删除吗?", new CallBack() {@Overridepublic void isConfirm(boolean flag) {// TODO Auto-generated method stubSystem.out.println("----->>" + flag);if (flag) {//dosomething.....判断执行业务逻辑}}});}});button2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stub CustomDialog dialog = new CustomDialog(MainActivity.this); // LayoutInflater layoutInflater = getLayoutInflater(); dialog.createToasts("网络有有异常!!",getLayoutInflater()); }});}@Overridepublic 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;}}
0 0
- android自定义对话框工具类
- 【工具类】Android自定义提示框、对话框、加载框
- Android—关于自定义对话框的工具类
- 【工具类】自定义弹出对话框
- Android自定义适配器父类继承BaseAdapter,自定义生成对话框工具类
- android中的对话框:自定义对话框
- Android Dialog( 自定义对话框)
- android 自定义对话框
- android自定义对话框
- Android自定义对话框
- android 自定义对话框
- Android自定义Dialog对话框
- android自定义大小对话框
- android自定义对话框
- Android自定义对话框
- android 自定义对话框
- android 自定义对话框
- android自定义对话框
- xml命名空间详解
- 认识js中的function和this---new Function(a,b,body)方式
- 为什么许多卓越的科学家却是虔诚的基督徒之我见(西方文化史作业)
- javascript 悬浮跟随框缓动效果
- JavaScript程序员必备的5个debug技巧
- android自定义对话框工具类
- Android上的断点续传下载
- springMVC入门
- 天气总是这样变化无常
- android父View手势和子View的点击事件处理
- 容斥原理 进阶
- 注意!Qt的Json库解析有问题,请服务端转好string再过来
- 女孩不要老是熬夜对身体不好
- 20141124