android开发:具有选择功能的对话框

package irdc.ex03_20;

 

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

 

public class EX03_20 extends Activity
{
  public Button mButton1;
  public TextView mTextView1;
 
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   
    mButton1 =(Button) findViewById(R.id.myButton1);
    mTextView1 = (TextView) findViewById(R.id.myTextView1);
    mButton1.setOnClickListener(myShowAlertDialog);
  }
 
  Button.OnClickListener myShowAlertDialog = new Button.OnClickListener()
  {
    public void onClick(View arg0)
    {
      new AlertDialog.Builder(EX03_20.this)
        .setTitle(R.string.str_alert_title)
        .setItems(R.array.items_irdc_dialog,
        new DialogInterface.OnClickListener()
        {
          public void onClick(DialogInterface dialog, int whichcountry)
          {
            CharSequence strDialogBody = getString(R.string.str_alert_body);
            String[] aryShop =
            getResources().getStringArray(R.array.items_irdc_dialog);                                          
              new AlertDialog.Builder(EX03_20.this)                       
              .setMessage(strDialogBody + aryShop[whichcountry])                       
              .setNeutralButton(R.string.str_ok, new DialogInterface.OnClickListener()
              {
                public void onClick(DialogInterface dialog, int whichButton)
                {
                  /*在这里处理要做的事*/
                }
              })
              .show();
          }
        })
        .setNegativeButton("", new DialogInterface.OnClickListener()
        {
          @Override
          public void onClick(DialogInterface d, int which)
          {
            d.dismiss();
          }
        })
        .show();
    } /*End: public void onClick(View arg0)*/
  };
}

 

res/values/strings.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="hello">IRDC本週聚餐哪裡打牙祭?</string>
  <string name="app_name">EX03_20</string>
  <string name="str_button1">按我開始選擇</string>
  <string name="str_alert_title">按我開始選擇</string>
  <string name="str_alert_body">你選擇的是:</string>
  <string name="str_ok">確認</string>
  <array name="items_irdc_dialog">
    <item>萌點女僕餐廳</item>
    <item>一鍋日式小火鍋</item>
    <item>好吃國巴西窯烤</item> 
  </array>
</resources>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值