0

ギャラリーから選択された画像のリストを GridView レイアウトに取り込むコードを以下に示します。写真は GridView レイアウトに問題なく表示されますが、問題は、アプリを閉じるか、ギャラリーから別の写真を選択すると、これらの写真が消えることです。

誰かが私を正しい方向に向けてくれませんか?

どんな助けでも大歓迎です。

コード:

public class MainActivity extends Activity {

   GridView gridGallery;
   Handler handler;
   Gallery_Adapter_Activity adapter;

   Button btnGalleryPick;
   Button btnGalleryPickMul;

   String action;
   ViewSwitcher viewSwitcher;
   ImageLoader imageLoader;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);

    initImageLoader();
    init();
}

private void initImageLoader() {
    @SuppressWarnings("deprecation")
    DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
            .bitmapConfig(Bitmap.Config.RGB_565).build();
    ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
            this).defaultDisplayImageOptions(defaultOptions).memoryCache(
            new WeakMemoryCache());

    ImageLoaderConfiguration config = builder.build();
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);
}

private void init() {

    handler = new Handler();
    gridGallery = (GridView) findViewById(R.id.gridGallery);
    gridGallery.setFastScrollEnabled(true);                     
    adapter = new Gallery_Adapter_Activity(getApplicationContext(), imageLoader);
    adapter.setMultiplePick(false);
    gridGallery.setAdapter(adapter);

    viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
    viewSwitcher.setDisplayedChild(1);


    Button done_button = (Button) findViewById(R.id.done);      
    done_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {       
            finish();                           
        }                       
    });


    btnGalleryPickMul = (Button) findViewById(R.id.btnGalleryPickMul);
    btnGalleryPickMul.setOnClickListener(new View.OnClickListener() {                               

        @Override
        public void onClick(View v) {       //Add Images Button OnClickListener
            Intent i = new Intent(Multiple_Pick_Activity.ACTION_MULTIPLE_PICK);
            startActivityForResult(i, 12345);           
        }                           
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == result_requestcode && resultCode == Activity.RESULT_OK)

{       

SDcardPath_Activity SDcardPath_Class = new SDcardPath_Activity();

String[] ALL_Paths = data.getStringArrayExtra("all_path");

for (String single_path : ALL_Paths) 
{      

    SQ_LITE_DATABASE.addImageFile(single_path);           

}

try { 


ArrayList<SDcardPath_Activity> SQLite_Databse_Data = SQ_LITE_DATABASE.readImageFiles();
SQLite_Databse_Data.add(SDcardPath_Class);

viewSwitcher.setDisplayedChild(0);
adapter.addAll(SQLite_Databse_Data);        

Intent intent = new Intent (Image_MainActivity.this, Image_MainActivity.class);
startActivity(intent);
finish();

  } catch (Exception e) 
  {
   e.printStackTrace();
   return;

  }
 }       
}

編集:上記の作業コードを投稿

4

3 に答える 3

1

これらを onActivityResult に入れます。

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == result_requestcode && resultCode == Activity.RESULT_OK)

    {       

    SDcardPath_Activity SDcardPath_Class = new SDcardPath_Activity();

    String[] ALL_Paths = data.getStringArrayExtra("all_path");

    for (String single_path : ALL_Paths) 
    {      

        SQ_LITE_DATABASE.addImageFile(single_path);           

    }

 try { 


    ArrayList<SDcardPath_Activity> SQLite_Databse_Data = SQ_LITE_DATABASE.readImageFiles();
    SQLite_Databse_Data.add(SDcardPath_Class);

    viewSwitcher.setDisplayedChild(0);
    adapter.addAll(SQLite_Databse_Data);        

    Intent intent = new Intent (Image_MainActivity.this, Image_MainActivity.class);
    startActivity(intent);
    finish();

   } catch (Exception e) 
   {
    e.printStackTrace();
    return;

   }
  }       
 }
于 2014-06-04T12:34:59.747 に答える