In android , how to create Dialog with select option by using UI.
First you must be create new project by using following steps
public class SelectOptionItem extends Activity{
@Override
protected void onCreate(Bundle icircle) {
super.onCreate(icircle);
setContentView(R.layout.main);
final String items[] = {"item1","item2","item3"};
AlertDialog.Builder builder=new AlertDialog.Builder(SelectOptionItem.this);
builder.setTitle("Title");
builder.setSingleChoiceItems(items, 0,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// You can write here OnClick Action
}
})
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// You can write here OnClick OK Action
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
});
builder.show();
}
}
First you must be create new project by using following steps
- Create new project name : SelectOptionItem
- Go to Java file then type following Java code.
public class SelectOptionItem extends Activity{
@Override
protected void onCreate(Bundle icircle) {
super.onCreate(icircle);
setContentView(R.layout.main);
final String items[] = {"item1","item2","item3"};
AlertDialog.Builder builder=new AlertDialog.Builder(SelectOptionItem.this);
builder.setTitle("Title");
builder.setSingleChoiceItems(items, 0,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// You can write here OnClick Action
}
})
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// You can write here OnClick OK Action
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
});
builder.show();
}
}
0 comments
Thanks for your comment