Monday 6 October 2014

Custom dialog box in android






1. Create alert.Xml 

    In side alert.xml
         1.alert_list
         2.btn_alert_bttntwo




private String  SelectmonthDialogButtonClick( ) {

final Dialog lDialog = new Dialog(Activity.this,
android.R.style.Theme_Translucent_NoTitleBar);
lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
lDialog.setContentView(R.layout.alert);
lDialog.setCanceledOnTouchOutside(false);
final ListView alert_list=(ListView) lDialog.findViewById(R.id.alert_list);
Button btn_alert_bttntwo=(Button) lDialog.findViewById(R.id.btn_alert_bttntwo);


btn_alert_bttntwo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
lDialog.cancel();
}
});


final String[] choiceList={"JAN","FEB","MAR"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
choiceList );

alert_list.setAdapter(arrayAdapter);
alert_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

// ListView Clicked item index
int itemPosition     = position;

// ListView Clicked item value
String month    = (String) alert_list.getItemAtPosition(position);

// position which clicked

int selected=position;

if (selected ==0){
// Action on first item click
lDialog.cancel();
}else if (selected ==1) {
// Action on second item click
lDialog.cancel();
}
else if (selected ==2) {
// Action on third item click
lDialog.cancel();
}
}

});

lDialog.show();
return "";
}

No comments:

Post a Comment

How to do text writing animation?  In Android Development we do not have the option to use any other custom font in our default Tex...