我目前正在尝试使用自定义布局文件“details.xml”弹出一个AlertDialog框,其中包含有关电影的信息。我觉得这可能就是我如何使用AlertDialog来填充这些字段,但我不确定如何最好地处理它。
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> Parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Movie mTemp = movieArray.get(position);
//Intent intent = new Intent(getApplicationContext(), SingleItemList.class);
AlertDialog.Builder builder = new AlertDialog.Builder(MovieList.this);
builder.setView(getLayoutInflater().inflate(R.layout.details, null));
builder.setTitle("Details");
builder.setNeutralButton("Post to Facebook", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
}
});
AlertDialog d = builder.create();
if (mTemp != null) {
ImageView image = (ImageView) d.findViewById(R.id.detailIcon);
TextView title = (TextView) d.findViewById(R.id.detailTitle);
TextView year = (TextView) d.findViewById(R.id.detailYear);
TextView rating = (TextView) d.findViewById(R.id.detailRating);
TextView director = (TextView) d.findViewById(R.id.detailDirector);
if (title != null) {
title.setText("Name: " + mTemp.title);
}
if(year != null) {
year.setText("Year: " + mTemp.year);
}
if(rating != null) {
rating.setText("Rating: " + mTemp.rating + "/10");
}
if(director != null) {
director.setText("Director: " + mTemp.director);
}
if(image != null) {
image.setImageBitmap(getBitmap(mTemp.coverURL));
}
}
d.show();
/*
Dialog dialog = new Dialog(MovieList.this);
dialog.setTitle("Details");
dialog.setContentView(R.layout.details);
dialog.show();*/
}
});
答案 0 :(得分:1)
您尚未发布LogCat错误,但我认为是(mTemp != null)
阻止导致问题的阻止。更改膨胀的视图,然后将其传递给setView()
。
View view = getLayoutInflater().inflate(R.layout.details, null);
if (mTemp != null) {
ImageView image = (ImageView) view.findViewById(R.id.detailIcon);
TextView title = (TextView) view.findViewById(R.id.detailTitle);
...
}
AlertDialog.Builder builder = new AlertDialog.Builder(MovieList.this);
builder.setTitle("Details");
builder.setView(view);
builder.setNeutralButton("Post to Facebook", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
}
});
AlertDialog d = builder.create();
d.show();