zoukankan      html  css  js  c++  java
  • 点击一个按钮,弹出一个对话框,对弹出的对话框进行配置

    activity 代码package com.dialog.test1; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.widget.Button; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; publicclass DialogTest1 extends Activity { /** Called when the activity is first created. */ private Button btn; private String TAG="DialogTest1"; @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn=(Button)findViewById(R.id.button1); btn.setOnClickListener(mylistener); } private OnClickListener mylistener=new OnClickListener(){ @Override publicvoid onClick(View v) { // TODO Auto-generated method stub //按了button按钮以后,让他弹出一个对话框 new AlertDialog.Builder(DialogTest1.this) .setIcon(R.drawable.icon) .setTitle(R.string.title_name) .setMessage(R.string.message_name) .setPositiveButton(R.string.btn1_name, new DialogInterface.OnClickListener(){ @Override publicvoid onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Log.v(TAG,"你点击了确定"); //activity finish finish(); } }) .show(); } }; @Override protectedvoid onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.v(TAG,"activity finish"); } }main.xml代码<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="按我会显示对话框哦!"/> </LinearLayout> string.xml代码<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, DialogTest1!</string> <string name="app_name">DialogTest1</string> <string name="title_name">我是标题</string> <string name="message_name">我是message</string> <string name="btn1_name">确定</string> <string name="btn2_name">取消</string> </resources>log 信息 V/DialogTest1( 2244): 你点击了确定 V/DialogTest1( 2309): activity finish 如果不加finish这句话,点完确定之后,对话框也会消失。   http://www.cnblogs.com/snowdrop/articles/1893594.html
  • 相关阅读:
    去 抚仙湖 和 去 洱海 差不多
    开源项目 D++
    未来 的 科学家, 不仅 是 数学家, 也是 系统设计 大师
    出一道 智商题 : 证明 永动机 是否 能 设计出来 ?
    评论一下 “推倒数学大厦”的 一个 作业题
    用 无穷级数 的 思路 三等分角
    三等分角 化圆为方 可以 考虑 用 无穷级数 的 方式 来 实现
    CPU 应该 搞 0 级 Cache , 而不是 大寄存器
    关于 智商 (2)
    关于 智商
  • 原文地址:https://www.cnblogs.com/adodo1/p/4327216.html
Copyright © 2011-2022 走看看