View

Wednesday 4 May 2011

Dialog List Item


I use a Button click to show a  dialog to select a multiple option using radio buttons.

[sourcecode language="java"]

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;

public class DialogListView extends Activity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        final Button clk=(Button)findViewById(R.id.button1);
        clk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub


final String items[] = {"5 minutes","15 minutes","30 minutes"};

       AlertDialog.Builder ab=new AlertDialog.Builder(ExampleApp.this);
       ab.setTitle("Title");
       ab.setSingleChoiceItems(items, 0,new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int whichButton) {
       // onClick Action
       
       
       }
       })
       .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int whichButton) {
       // on Ok button action
       
        //ab.setOnItemSelectedListener(arg0);
        //clk.getSelectionStart();
        //clk.setSingleLine();
                 
       }
       })
       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int whichButton) {
       // on cancel button action
       }
       });
       ab.show();
     
     



}
});
       
        [/sourcecode]

The output will looks like
       
       
    }
}




No comments:

Post a Comment