Android Radio, multi-select pop-up menu

Source: Internet
Author: User

Menu Radio window:

Import android.app.Activity;
Import Android.app.AlertDialog;
Import Android.content.DialogInterface;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ListView;
Import Android.widget.Toast;

public class Mainactivity extends Activity {
Private string[] areas = new string[]{"All", "Magnolia Fragrant Garden", "Zhangjiang subway station", "Golden Section Road", "Zhangjiang Road", "Crape Myrtle Road", "Xiang nan xiao qu"};
Private boolean[] Areastate=new Boolean[]{true, False, False, False, False, false,false};
Private Radioonclick Radioonclick = new Radioonclick (1);
Private ListView Areachecklistview;
Private ListView Arearadiolistview;
Private Button Alertbutton;
Private Button Checkboxbutton;
Private Button RadioButton;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

alertbutton= (Button) Findviewbyid (R.id.alertbutton);
checkboxbutton= (Button) Findviewbyid (R.id.checkboxbutton);
radiobutton= (Button) Findviewbyid (R.id.radiobutton);

Alertbutton.setonclicklistener (New Alertclicklistener ());
Checkboxbutton.setonclicklistener (New Checkboxclicklistener ());
Radiobutton.setonclicklistener (New Radioclicklistener ());
}
/**
* Menu pop-up window
* @author XMZ
*
*/
Class Alertclicklistener implements onclicklistener{
@Override
public void OnClick (View v) {
New Alertdialog.builder (Mainactivity.this). Settitle ("Select Area"). Setitems (Areas,new Dialoginterface.onclicklistener () {
public void OnClick (Dialoginterface dialog, int which) {
Toast.maketext (Mainactivity.this, "You have selected:" + which + ":" + Areas[which],toast.length_long). Show ();
Dialog.dismiss ();
}
}). Show ();
}
}
/**
* Multi-Marquee popup Menu window
* @author XMZ
*
*/
Class Checkboxclicklistener implements onclicklistener{
@Override
public void OnClick (View v) {
Alertdialog ad = new Alertdialog.builder (mainactivity.this)
. Settitle ("Select Region")
. Setmultichoiceitems (Areas,areastate,new Dialoginterface.onmultichoiceclicklistener () {
public void OnClick (Dialoginterface dialog,int Whichbutton, Boolean isChecked) {
Click an area
}
}). Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
public void OnClick (Dialoginterface dialog,int whichbutton) {
String s = "you selected:";
for (int i = 0; i < areas.length; i++) {
if (Areachecklistview.getcheckeditempositions (). get (i)) {
s + = i + ":" + areachecklistview.getadapter (). GetItem (i) + "";
}else{
Areachecklistview.getcheckeditempositions (). get (I,false);
}
}
if (Areachecklistview.getcheckeditempositions (). Size () > 0) {
Toast.maketext (Mainactivity.this, S, Toast.length_long). Show ();
}else{
No choice
}
Dialog.dismiss ();
}
}). Setnegativebutton ("Cancel", null). Create ();
Areachecklistview = Ad.getlistview ();
Ad.show ();
}
}

/**
* Single-Selection popup menu window
* @author XMZ
*
*/
Class Radioclicklistener implements Onclicklistener {
@Override
public void OnClick (View v) {
Alertdialog ad =new Alertdialog.builder (mainactivity.this). Settitle ("Select Region")
. Setsinglechoiceitems (Areas,radioonclick.getindex (), Radioonclick). Create ();
Arearadiolistview=ad.getlistview ();
Ad.show ();
}
}
/**
* Click on the Radio box event
* @author XMZ
*
*/
Class Radioonclick implements dialoginterface.onclicklistener{
private int index;

public radioonclick (int index) {
This.index = index;
}
public void Setindex (int index) {
This.index=index;
}
public int GetIndex () {
return index;
}

public void OnClick (dialoginterface dialog, int whichbutton) {
Setindex (Whichbutton);
Toast.maketext (Mainactivity.this, "You have selected:" + Index + ":" + Areas[index], Toast.length_long). Show ();
Dialog.dismiss ();
}
}
}

<?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"
>
<button
Android:id= "@+id/alertbutton"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "Menu Selection Window"
/>
<button
Android:id= "@+id/checkboxbutton"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Multiple Selection menu Selection window"
/>
<button
Android:id= "@+id/radiobutton"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:text= "Single-selection menu Selection window-1"
/>
</LinearLayout>

Android Radio, multi-select pop-up menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.