0

カスタムセルと各セルの異なる情報を使用して、リストビューの「Facebook」スタイルを生成しようとしています。すべてが正常に機能していますが、サムネイル画像ギャラリーの反応が非常に奇妙です。

ギャラリーは最初は表示されませんが、下にスクロールすると間違ったセルに表示され、もう一度上下にスクロールすると、間違ったセルにランダムに表示され続け、セルの1つで2倍になります(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();
        }
 }

コードのどこが悪いのかわかりません、何か提案はありますか?

4

1 に答える 1

0

JSON配列のデコードに使用するのと同じサイクル内で、必要に応じてすべてのセルを動的に生成する動作を修正しました。問題は、リストビューウィジェットを使用したときのセルのリサイクルが原因だと思いますが、100%ではありません。誰かがそれを確認できれば、それについては確かです。

私が知りたいのは、パフォーマンスの観点から、リストビューウィジェットを使用することに対する私のアプローチに大きな違いがあるかどうかです。

于 2012-12-03T03:44:29.120 に答える