//////////////// Normal Alert Dialog ///////////////////////
public static AlertDialog.Builder getAlertDialog(Activity activity,String msg)
{
AlertDialog.Builder builder=new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
builder.setTitle("Message");
builder.setMessage(msg);
builder.setIcon(R.drawable.logo_small);
builder.setCancelable(false);
DialogInterface.OnClickListener listener=new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
};
builder.setPositiveButton("OK", listener);
return builder;
}
/////////////// Custome Alert Dialog Which contains Bullets ///////////////
Step 1> Create a xml file which contains ListView as below with the name of dialog_list_bullets.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#5B5B5B"
android:dividerHeight="1dp"
>
</ListView>
</LinearLayout>
Step 2> Call that Alert Dialo from Any location By passing input parameter as a Activity name and String message which is seperated with ",".
public static AlertDialog.Builder getAlertDialogWithBullets(Activity activity,String msg)
{
ArrayList<String> list=new ArrayList<String>();
StringTokenizer tokenizer=new StringTokenizer(msg, ",");
while(tokenizer.hasMoreElements())
{
list.add(tokenizer.nextToken()) ;
}
AlertDialog.Builder alertdialog = new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
LayoutInflater inflater = activity.getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.dialog_list_bullets, null);
alertdialog.setView(convertView);
alertdialog.setTitle("Message");
alertdialog.setCancelable(false);
alertdialog.setIcon(R.drawable.logo_small);
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
lv.setAdapter(new BulletsAdapter(activity, list));
DialogInterface.OnClickListener listener=new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
};
alertdialog.setPositiveButton("OK", listener);
return alertdialog;
}
public static AlertDialog.Builder getAlertDialog(Activity activity,String msg)
{
AlertDialog.Builder builder=new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
builder.setTitle("Message");
builder.setMessage(msg);
builder.setIcon(R.drawable.logo_small);
builder.setCancelable(false);
DialogInterface.OnClickListener listener=new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
};
builder.setPositiveButton("OK", listener);
return builder;
}
/////////////// Custome Alert Dialog Which contains Bullets ///////////////
Step 1> Create a xml file which contains ListView as below with the name of dialog_list_bullets.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#5B5B5B"
android:dividerHeight="1dp"
>
</ListView>
</LinearLayout>
Step 2> Call that Alert Dialo from Any location By passing input parameter as a Activity name and String message which is seperated with ",".
public static AlertDialog.Builder getAlertDialogWithBullets(Activity activity,String msg)
{
ArrayList<String> list=new ArrayList<String>();
StringTokenizer tokenizer=new StringTokenizer(msg, ",");
while(tokenizer.hasMoreElements())
{
list.add(tokenizer.nextToken()) ;
}
AlertDialog.Builder alertdialog = new AlertDialog.Builder(activity, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
LayoutInflater inflater = activity.getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.dialog_list_bullets, null);
alertdialog.setView(convertView);
alertdialog.setTitle("Message");
alertdialog.setCancelable(false);
alertdialog.setIcon(R.drawable.logo_small);
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
lv.setAdapter(new BulletsAdapter(activity, list));
DialogInterface.OnClickListener listener=new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
};
alertdialog.setPositiveButton("OK", listener);
return alertdialog;
}
No comments:
Post a Comment