android - Get dialoginterface of an alertdialog click -
i need alertdialog custom view in title. since not able inflate view title used this link. able make custom title , able inflate list items. on list item click alertdialog not closing. how implement this?
package com.qustom.dialog; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener; import android.graphics.color; import android.graphics.drawable.drawable; import android.view.view; import android.widget.adapterview; import android.widget.framelayout; import android.widget.imageview; import android.widget.listadapter; import android.widget.listview; import android.widget.textview; public class qustomdialogbuilder extends alertdialog.builder { private view mdialogview; private textview mtitle; private imageview micon; private textview mmessage; boolean firsttime = true; private view mdivider; private context mcontext; public qustomdialogbuilder(context context) { super(context); mdialogview = view .inflate(context, r.layout.qustom_dialog_layout, null); setview(mdialogview); mtitle = (textview) mdialogview.findviewbyid(r.id.alerttitle); mmessage = (textview) mdialogview.findviewbyid(r.id.message); micon = (imageview) mdialogview.findviewbyid(r.id.icon); mdivider = mdialogview.findviewbyid(r.id.titledivider); mcontext = context; } //this add listview public qustomdialogbuilder setcustomadapter(listadapter adapter, final onclicklistener listener) { listview listview = new listview(mcontext); listview.setadapter(adapter); ((framelayout) mdialogview.findviewbyid(r.id.custompanel)) .addview(listview); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { qustomdialogbuilder dialog = qustomdialogbuilder.this; if (dialog != null) { log.d("skt", "dialog in custom not null");//this log working } listener.onclick( null, arg2);//here want dialoginterface object. stuck } }); return this; } public qustomdialogbuilder setdividercolor(string colorstring) { mdivider.setbackgroundcolor(color.parsecolor(colorstring)); return this; } @override public qustomdialogbuilder settitle(charsequence text) { mtitle.settext(text); return this; } public qustomdialogbuilder settitlecolor(string colorstring) { mtitle.settextcolor(color.parsecolor(colorstring)); return this; } @override public qustomdialogbuilder setmessage(int textresid) { mmessage.settext(textresid); return this; } @override public qustomdialogbuilder setmessage(charsequence text) { mmessage.settext(text); return this; } @override public qustomdialogbuilder seticon(int drawableresid) { micon.setimageresource(drawableresid); return this; } @override public qustomdialogbuilder seticon(drawable icon) { micon.setimagedrawable(icon); return this; } public qustomdialogbuilder setcustomview(int resid, context context) { view customview = view.inflate(context, resid, null); ((framelayout) mdialogview.findviewbyid(r.id.custompanel)) .addview(customview); return this; } @override public alertdialog show() { if (mtitle.gettext().equals("")) mdialogview.findviewbyid(r.id.toppanel).setvisibility(view.gone); return super.show(); } }
can me?
i know can set customview title setcustomtitle(view) method. problem this
if check android document there no dismiss or cancel method in alertdialog.builder class so, if want dismiss need object of alertdialog when override show method of alertdialog.builder. after have call alertdilogobject.dismiss() method in list item click. hope answer helpful you.
Comments
Post a Comment