zoukankan      html  css  js  c++  java
  • android 带RadioButton的Dialog

    package com.example.dialog3;

    import android.os.Bundle;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.DialogInterface;
    import android.view.Menu;
    import android.widget.Toast;

    public class MainActivity extends Activity {
    private int selectedFruitIndex = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final String[] Fruit = new String[] {"苹果", "橘子", "草莓", "香蕉"};

    Dialog myDialog = new AlertDialog.Builder(this)
    .setTitle("标题")
    .setIcon(R.drawable.ic_launcher)
    .setSingleChoiceItems(Fruit, 0, new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    selectedFruitIndex=which;
    Toast.makeText(MainActivity.this, Fruit[which], Toast.LENGTH_SHORT).show();
    }
    })
    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    //
    }
    })
    .setNegativeButton("取消", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub

    }
    })
    .setNeutralButton("详情", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub

    }
    })
    .create();

    myDialog.show();
    }

    @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;
    }

    }

  • 相关阅读:
    [BZOJ5338][TJOI2018]xor(可持久化Trie)
    [BZOJ4592][SHOI2015]脑洞治疗仪(线段树)
    [BZOJ4571][SCOI2016]美味(贪心+主席树)
    [BZOJ4570][SCOI2016]妖怪(凸包)
    [BZOJ4569][SCOI2016]萌萌哒(倍增+并查集)
    [BZOJ4567][SCOI2016]背单词(Trie+贪心)
    [BZOJ4565][HAOI2016]字符合并(区间状压DP)
    [BZOJ4561][JLOI2016]圆的异或并(扫描线)
    [BZOJ2650]积木
    [清橙A1210]光棱坦克
  • 原文地址:https://www.cnblogs.com/honeynm/p/4242241.html
Copyright © 2011-2022 走看看