[Java for Android App Development] sak-venom1997:
Hi everyone I'am using to grid view when i click an item on grid view 1 it should be added to grid view 2

It is added but the grid view one is scrambled up

Here is the code

mImageViews = new ArrayList<WeakReference<ImageView>>();
private ArrayList<String> mImageRepositoryTh = new ArrayList<String>(); //Thumbnails size image paths
private ArrayList<String> mImageRepositoryFu = new ArrayList<String>();//Full size image paths

private ArrayList<WeakReference<ImageView>> mWeakReferences = new ArrayList<WeakReference<ImageView>>();
private GridView mListView;
private GridView mSelected;

mListView = (GridView)findViewById(R.id.images_view);
mListView.setAdapter(new ImageAdapter(this));

mSelected = (GridView)findViewById(R.id.images_view_sel);

mChecked = new boolean[mListView.getCount()];
Log.e("ERR", "Array Length "+String.valueOf(mChecked.length));

mListView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
mChecked[arg2] = !mChecked[arg2];
mWeakReferences.add(new WeakReference<ImageView>((ImageView)arg1));
mSelected.setAdapter(new SelectedImageAdapter());

}

});

Adapters

public class ImageAdapter extends BaseAdapter
{

public ImageAdapter(@SuppressWarnings("unused")Context c)
{

}

public int getCount() {
return mImageRepositoryTh.size();
}

public Object getItem(int position) {
return null;
}

public long getItemId(int position) {
return position;
}

private boolean loadingFailed = false;

public View getView(int position, View convertView, ViewGroup parent) {
final ImageView imageView;
if(convertView != null)
{
try
{
if (mImageViews.get(position).get() != null)
{
return mImageViews.get(position).get();

}
}
catch(IndexOutOfBoundsException E)
{
Log.e("Not Yet Inflate", "Array Index Out \n", E);
}
}
imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
mImageLoader.displayImage("file://"+mImageRepositoryTh.get(position), imageView, mOptions,new
ImageLoadingListener() {

public void onLoadingStarted(String imageUri, View view) {
// TODO Auto-generated method stub

}

public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
// TODO Auto-generated method stub
loadingFailed = true;
}

public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// TODO Auto-generated method stub

}

public void onLoadingCancelled(String imageUri, View view) {
// TODO Auto-generated method stub

}
});
if (loadingFailed) {
mImageLoader.displayImage("file://"+mImageRepositoryFu.get(position),imageView ,mOptions);
loadingFailed = false;
}
mImageViews.add(new WeakReference<ImageView>(imageView));
return imageView;
}
}

private class SelectedImageAdapter extends BaseAdapter
{

public SelectedImageAdapter()
{

}

[MENTION=439709]override[/MENTION]
public int getCount() {
return mWeakReferences.size();
}

[MENTION=439709]override[/MENTION]
public Object getItem(int i) {
return null;
}

[MENTION=439709]override[/MENTION]
public long getItemId(int i) {
return i;
}

[MENTION=439709]override[/MENTION]
public View getView(int position, View convertView, ViewGroup parent)
{
WeakReference<ImageView> iViewRef = mWeakReferences.get(position);
return iViewRef.get();
}
}

My apologies for ads

Download the apk from attachments