---------------------------------------------------------
dialog_customview.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="message description" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
---------------------------------------------------------
private Dialog mDialog = null;
public void showDialog(){
String[] itemArray = getItemArray();
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
LayoutInflater inflater = LayoutInflater.from(mContext);
View customView = inflater.inflate(R.layout.dialog_customview, null);
builder.setTitle("Message and List Dialog");
ListView lv = (ListView)customView.findViewById(R.id.list1);
lv.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_single_choice, itemArray));
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setOnItemClickListener(mItemClickListener);
builder.setView(customView);
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
mDialog = builder.create();
mDialog.setCancelable(false);
mDialog.setCanceledOnTouchOutside(false);
mDialog.setOnShowListener(new OnShowListener(){
@Override
public void onShow(DialogInterface arg0) {
setPositiveEnable(false);
}
});
mDialog.setOnDismissListener(new OnDismissListener(){
@Override
public void onDismiss(DialogInterface arg0) {
mDialog = null;
}
});
//finally
mDialog.show();
}
public void setPositiveButtonEnable(boolean isEnable){
if(mDialog != null){
Button btn = ((AlertDialog) mDialog).getButton(AlertDialog.BUTTON_POSITIVE);
if(btn != null){
btn.setEnabled(isEnable);
}
}
}
'programmer > android' 카테고리의 다른 글
menu icon invalidate(enable/disable) (0) | 2013.07.11 |
---|---|
Using TabHost (0) | 2013.07.11 |
Using context menu on Linearlayout (0) | 2013.07.08 |
touch block (0) | 2013.07.08 |
status bar (0) | 2013.07.08 |