我正在尝试生成一个列表视图“facebook”样式,自定义单元格和每个单元格上的不同信息,一切正常,但缩略图库的反应非常奇怪。
画廊起初没有出现,但是当我向下滚动时,它出现在错误的单元格中,一旦我再次向上或向下滚动,它就会一直随机显示在错误的单元格中,并且它开始在其中一个单元格上加倍(显示 2,然后是 4,然后是 6……)
为此,我将线性布局(水平)动态添加到先前生成的线性布局(垂直)中,并根据需要生成图像视图并使缩略图可点击,以便在点击时显示完整尺寸的图片。
动态生成缩略图的代码工作正常,并且在我也使用它的另一个类上进行了测试,但是当我尝试在我的适配器中为自定义单元格使用它时没有向我显示图像。
缩略图的代码如下:
if(!numPics.equals("0")){
imageGallery(gT, userId, trainingId);
}
“imageGallery” void 的代码如下:
void imageGallery (LinearLayout gT, String userId, String trainingId){
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("trainingid" ,trainingId));
nameValuePair.add(new BasicNameValuePair("userid", userId));
String url = Common.thumbnail();
String strPic = Common.doPost(url, nameValuePair);
String fullImUrl = Common.fullImage();
String fullImValue = Common.doPost(fullImUrl, nameValuePair);
final Handler handler = new Handler();
try{
boolean fFlg2 = true;
final String[] arrayFile;
int startIdx1 = 0;
int endIdx1 = 0;
int startIdx2 = 0;
int endIdx2 = 0;
endIdx1 = fullImValue.indexOf(",", startIdx1);
endIdx2 = strPic.indexOf(",",startIdx2);
int ImageNum = Integer.valueOf(fullImValue.substring(startIdx1,endIdx1));
int ImageNum2 = Integer.valueOf(strPic.substring(startIdx2,endIdx2));
Log.d("string", "" + ImageNum2);
String fileNames = fullImValue.substring(endIdx1+1);
arrayFile = new String[ImageNum];
String fileNames2 = strPic.substring(endIdx2+1);
String strUrl2 = Common.server;
int niv = 0;
int nivrow = 0;
LinearLayout ll = new LinearLayout(FriendsDiaries.this);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
ll.setOrientation(LinearLayout.HORIZONTAL);
boolean rowFlg = true;
boolean row1Flg = true;
for (int i=0; i< ImageNum2; i++){
endIdx1 = fileNames.indexOf(",",startIdx1);
endIdx2 = fileNames2.indexOf(",",startIdx2);
String fileName = fileNames.substring(startIdx1,endIdx1);
String thumUrl = strUrl2 + fileNames2.substring(startIdx2,endIdx2);
arrayFile[i] = fileName;
startIdx1 = endIdx1+1;
ImageView iv = new ImageView(FriendsDiaries.this);
Bitmap bmImg = null;
URL myFileUrl =null;
try {
myFileUrl= new URL(thumUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
final int position2 = niv;
niv++;
final int selectNum = position2;
iv.setImageBitmap(bmImg);
iv.setId(i+1);
final int id_ = iv.getId();
Log.e("a1", ""+ id_);
iv.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
handler.post(new Runnable(){
public void run(){
moveScreen(arrayFile, selectNum);
}
});
}
});
nivrow++;
if(ImageNum2 > 4){
if(row1Flg){
if(nivrow<=4){
ll.addView(iv, llp);
if(nivrow==4){
rowFlg = false;
row1Flg = false;
nivrow = 0;
gT.addView(ll);
}else if(niv == ImageNum2){
gT.addView(ll);
}
}
}else if(rowFlg == false){
LinearLayout nll = new LinearLayout(FriendsDiaries.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
nll.setOrientation(LinearLayout.HORIZONTAL);
ll = nll;
rowFlg = true;
ll.addView(iv, lp);
if(niv == ImageNum2){
gT.addView(ll);
}
}else{
if(nivrow<=4){
ll.addView(iv,llp);
if(nivrow==4){
rowFlg = false;
nivrow = 0;
gT.addView(ll);
}else if(niv == ImageNum2){
gT.addView(ll);
}
}
}
}else{
ll.addView(iv,llp);
Log.w("string", ""+niv);
if(niv == ImageNum2){
gT.addView(ll);
boolean test = true;
Log.i("string", ""+ test);
}
}
} catch (IOException e) {
e.printStackTrace();
}
if(fFlg2){
startIdx2 += endIdx2+1;
}else{
startIdx2 = endIdx2+1;
}
fFlg2 = false;
}
}catch (Exception e) {
e.printStackTrace();
}
}
我找不到代码有什么问题,有什么建议吗?