android自定义对话框工具类
2018-07-20 来源:open-open
public class CustomDialog { private AlertDialog.Builder builder; private Context context; public CustomDialog(Context context) { // TODO Auto-generated constructor stub this.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() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub callBack.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; @Override protected 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() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub CustomDialog dialog = new CustomDialog(MainActivity.this); dialog.createDialog("确定", "提示", "您确定要删除吗?", new CallBack() { @Override public void isConfirm(boolean flag) { // TODO Auto-generated method stub System.out.println("----->>" + flag); if (flag) { //dosomething.....判断执行业务逻辑 } } }); } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub CustomDialog dialog = new CustomDialog(MainActivity.this); // LayoutInflater layoutInflater = getLayoutInflater(); dialog.createToasts("网络有有异常!!",getLayoutInflater()); } }); } @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; } }
标签: 网络
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇: android圆角矩形的实现
下一篇: android Json解析全
最新资讯
热门推荐