我需要一个带有标题自定义视图的警报对话框。由于我无法将视图膨胀为标题,因此我使用了此链接。我能够制作自定义标题并能够膨胀列表项。但是在列表项上单击警报对话框没有关闭。如何实施?
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 is where I 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 is working
}
listener.onClick( null, arg2);//Here I want the DialogInterface Object. this is where I am 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();
}
}
谁能帮我?
我知道我可以通过 setCustomTitle(view) 方法将自定义视图设置为标题。但我的问题是这个