我尝试将图像延迟加载到对话框内的图像。
我的问题是我无法从对话框外部的对话框中获取视图来更新图像。
我尝试给每个视图唯一的 id,然后通过它的 id 找到视图,但我得到空指针异常。
这是我的对话框代码:
public void showAllComents() {
builderComment = new AlertDialog.Builder(this);
builderComment.setTitle(dietsList[poisition][0] + " comments");
View prefView = View.inflate(this, R.layout.show_comments, null);
builderComment.setCancelable(false);
editComment = (EditText) prefView.findViewById(R.id.editComment);
LinearLayout commentsLinear = (LinearLayout) prefView.findViewById(R.id.commentsLinear);
if (haveComments) {
int length = comments.length;
for (int i = 0; i < length; i++)
{
LinearLayout tempLinear = new LinearLayout(this);
LayoutParams p1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
if (i != 0)
p1.setMargins(0, 20, 0, 0);
tempLinear.setOrientation(LinearLayout.HORIZONTAL);
tempLinear.setLayoutParams(p1);
ImageView image = new ImageView(this);
p1 = new LayoutParams(64, 64);
image.setLayoutParams(p1);
image.setId(6000+i);
image.setImageDrawable(getResources().getDrawable(R.drawable.anonymous));
tempLinear.addView(image);
commentsLinear.addView(tempLinear);
}
...
...
... \\\Rest of dialog code...
我加载我的图像,然后我尝试更新图像视图。
public void setCommentedUsersProfilePictrue()
{
int lengthUnique = commentsuniqueNames.length;
int loadLength = comments.length;
View prefView = View.inflate(this, R.layout.show_comments, null);
for(int i = 0; i < loadLength; i++)
{
for(int j = 0; j < lengthUnique; j++)
{
if(comments[i][1].equals(commentsuniqueNames[j]))
{
Log.i("user name comment", comments[i][1]);
//Log.i("user name", userProfilePictures[i][1]);
ImageView tempImage = new ImageView(DietWall.this);
tempImage = (ImageView) prefView.findViewById(6000 + i);
if(tempImage != null && commentsLoadedPictrues[j][1] != null && commentsLoadedPictrues[j][1].equals("null") == false && commentsLoadedPictrues[j][1].equals("NULL") == false)
tempImage.setImageDrawable(new BitmapDrawable(getResources(),decodeBase64(commentsLoadedPictrues[j][1])));
else
Log.i("null", "null");
}
}
}
}