0

私は画像を選択し、画像のパスをArrayListに書き込むことができるカスタムギャラリーを持っています。カスタム ギャラリーは、onActivityResult インテントを使用して MainActivity クラスから呼び出されます。問題は、カスタム ギャラリーでは ArrayList が正しく (4 つの画像を選択すると、ArrayList の Imagepath を使用して 4 つの文字列を取得する)、ギャラリーから ArrayList を MainActivity に戻すと、ImagePath が 1 つしか残っていないことです。 ArrayList...助けてくれることを願っています...

MainActivity.java でアクティビティを開始します

Intent in = new Intent(getApplicationContext(), AndroidCustomGalleryActivity.class);
startActivityForResult(in, 500);

カスタム ギャラリーの ArrayList に入力し、Intent を Main に送り返します。

final Button selectAll = (Button) findViewById(R.id.selectAll);
    selectAll.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final int thmbnls = thumbnailsselection.length;
            //CheckBox cb = (CheckBox)findViewById(R.id.itemCheckBox);
            //int cbId = cb.getId();

            all = true;
            String allstring = String.valueOf(all);
            Log.d("BOOLONCLICK", allstring);

            for(int i =0; i<thmbnls; i++)
            {
                thumbnailsselection[i] = true;

                path = new ArrayList<String>();
                path.add(arrPath[i]);
                String test = path.toString();
                Log.d("ArrayList", test);
                pfade = path.toArray(new String[path.size()]);
            }

            Intent intent = new Intent();
            intent.putStringArrayListExtra("values", path);
            setResult(RESULT_OK, intent);
            finish();
        }
    });

Main でインテントを受け取ります。

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch(requestCode){
    case 500:
        if(resultCode == RESULT_OK){


            pfade = (ArrayList<String>) data.getStringArrayListExtra("values");
            //Log.d("SINGLEPFADE", pfade[0]);
            //filePath = (TextView)findViewById(R.id.idTxtImagePath);
            //int bilder = pfade.size();
            String test = pfade.toString();
            //filePath.setText(bilder);
            //String test = String.valueOf(bilder);
            Log.d("AnzahlBilder", test);
        }
        break;
    }


}
4

2 に答える 2

2

ArrayListループの内側を再現するから

この行を移動します:

path = new ArrayList<String>();

forループの前に

于 2013-09-29T13:20:16.730 に答える
0

for ループの前にコードを移動する必要があります。そうすれば、問題はなくなります。

...
path = new ArrayList<String>();
for (int i = 0; i < thmbnls; i++) {
    thumbnailsselection[i] = true;
    path = new ArrayList<String>();
    path.add(arrPath[i]);
    String test = path.toString();
    Log.d("ArrayList", test);
    pfade = path.toArray(new String[path.size()]);
}
...
于 2013-09-29T13:39:44.727 に答える