0
我嘗試將對話框中的圖像延遲加載圖像。從對話框外部獲取對話框內的視圖
我的問題是,我不能從我的對話框以外的對話框更新圖像的視圖。
我嘗試給每個視圖唯一的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...
我打開我的圖像,然後我嘗試更新imageviews。
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");
}
}
}
}
在這裏發表您的logcat .. –
我的日誌是(「空」,「空」) – dasdasd