我有一个适配器类,它将项目的ArrayList加载到ListView中。它做得很好。每当在ListView项中单击超链接文本时,我还尝试在ListView中创建一个项目的AlertDialog弹出窗口,引用特定的ListView项。但是,当我显示AlertDialog时,对话框顶部会出现黑屏,覆盖所有内容。
从我到目前为止在其他帖子上看到的问题可能是因为ListView项已经在ListView中膨胀而我试图在AlertDialog中重新填充它。如果那是问题,那么我怎样才能获得对已经膨胀的ListView项的引用,在AlertDialog中显示它,所有这些都来自适配器类。
这是一张正在发生的事情的图片。
以下是我的适配器类的以下代码。
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
listView = inflater.inflate(R.layout.list_item_reply, null);
TextView textView_name = (TextView) listView.findViewById(R.id.textViewName);
TextView textView_time = (TextView) listView.findViewById(R.id.textViewTime);
TextView textView_title = (TextView) listView.findViewById(R.id.textViewThreadTitle);
textView_name.setText(this.reply_list.get(position).getName());
textView_time.setText(this.reply_list.get(position).getTime_diff() + " ago");
textView_title.setText(Html.fromHtml(reply_list.get(position).getTitle()));
Spannable clickableMessage = (Spannable) textView_message.getText();
clickableMessage = Find_String_Matches(clickableMessage);
textView_message.setText(clickableMessage, TextView.BufferType.SPANNABLE);
return listView;
}
private Spannable Find_String_Matches(Spannable text){
Pattern pattern = Pattern.compile(thread_regex);
Matcher matcher = pattern.matcher(text.toString());
while (matcher.find()) {
Log.d("start", "Start index: " + matcher.start());
Log.d("end", " End index: " + matcher.end());
Log.d("found", " Found: " + matcher.group());
text = addClickablePart(text, matcher.start(), matcher.end());
}
return text;
};
public void Popup_Thread(final int pos){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listReplyView = getView(pos, null, null);
dialogBuilder.setView(listReplyView);
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
};
答案 0 :(得分:2)
这应该有效。无需夸大布局
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);
builder.setMessage("Your message");
View listReplyView = getView(pos, null, null);
dialogBuilder.setView(listReplyView);
// Yes option
builder.setPositiveButton(R.string.positive_option,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//smth
}
});
// Cancel option
builder.setNegativeButton(R.string.negative_option,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); // If cancel is pressed, dialog is closed
}
});
// Show the dialog window
AlertDialog dialog = builder.create();
dialog.show();
答案 1 :(得分:1)
尝试给布局项目充气:
public void Popup_Thread(final int pos){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout. list_item_reply, null);
dialogBuilder.setView(dialogView);
// set value into textview
TextView textView_name = (TextView) dialogView.findViewById(R.id.textViewName);
TextView textView_time = (TextView)
dialogView.findViewById(R.id.textViewTime);
TextView textView_title = (TextView)
dialogView.findViewById(R.id.textViewThreadTitle);
textView_name.setText(this.reply_list.get(pos).getName());
textView_time.setText(this.reply_list.get(pos).getTime_diff() + " ago");
textView_title.setText(Html.fromHtml(reply_list.get(pos).getTitle()));
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
};
答案 2 :(得分:1)
我有一个很好的魔法
创建与自定义ListView项目布局相同的布局,当您 show()时,您的对话框将获取当前项目并放入相同的布局并在对话框中对其进行充气
答案 3 :(得分:1)
请为对话提供transperent主题。
在values \ styles.xml
中添加以下样式
listView = inflater.inflate(R.layout.list_item_reply, R.styles.Theme.Transparent);

并提供......就像......
{{1}}