1

Sorry for my english. There is a mini-gallery, when you click on an image from the gallery it should (picture) to open in full screen. App just throws by pressing the image. what am I doing wrong? MainActivity

public class MainAcTwo extends Activity {

@SuppressWarnings("deprecation")
Gallery gallery;
ImageView bigimage;

@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.two);
    gallery=(Gallery) findViewById(R.id.gallery);
    gallery.setAdapter(new ImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            long imageId = ImageAdapter.ThumbsIds[position];

           Intent fullScreenIntent = new Intent(v.getContext(), FullScreenImage.class);
           fullScreenIntent.putExtra(MainAcTwo.class.getName(), imageId);

          MainAcTwo.this.startActivity(fullScreenIntent); 

        }
    });
}

}

ImageAdapter

public class ImageAdapter extends BaseAdapter implements SpinnerAdapter {

private Context context;

public ImageAdapter(Context context) {
    // TODO Auto-generated constructor stub
    this.context = context;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return ThumbsIds.length;
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup arg2) {
    // TODO Auto-generated method stub
    ImageView imageView=null;
    if(convertView == null) {
        imageView = new ImageView(context);
        imageView.setLayoutParams(new Gallery.LayoutParams(215, 200));
        imageView.setPadding(8, 8, 8, 8);


    }else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(ThumbsIds[position]);

    return imageView;
}

public static Integer[] ThumbsIds={
    R.drawable.abs_icla,
    R.drawable.abs_dog,
    R.drawable.abs_flow,
    R.drawable.abs_neb,
    R.drawable.abs_rad
};

}

FullScreenImage

public class FullScreenImage extends Activity {

protected void onCreate(Bundle savedInstanceState) {
       setContentView(R.layout.full_image);
       Intent intent = getIntent();
       long imageId = (Long) intent.getExtras().get(FullScreenImage.class.getName());

       ImageView imageView = (ImageView) findViewById(R.id.fullImage);

       imageView.setLayoutParams( new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));

       imageView.setImageResource((int) imageId);
       imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}

}

nesalexy
  • 848
  • 2
  • 9
  • 30
  • 1
    What is the error it is throwing and in which line? – mthandr Sep 21 '14 at 14:32
  • When I click on the image, writes "Unfortunately, myProgect has stopped" In logCat: FATAL EXCEPTION: main java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams atandroid.widget.LinearLayout.measureVertical(LinearLayout.java:655) at android.widget.LinearLayout.onMeasure(LinearLayout.java:574) at android.view.View.measure at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:15172) ________________ – nesalexy Sep 21 '14 at 14:57
  • 1
    try cleaning the project and building. Maybe it is some confusing in the xml file because I don't see any Linear Layout, only a ImageView – mthandr Sep 21 '14 at 15:04
  • Example here http://stackoverflow.com/a/35886019/4395114 – Mansukh Ahir Mar 09 '16 at 08:03

1 Answers1

2

clean you project if it does not work

 imageView.setLayoutParams( new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));


change it to

 imageView.setLayoutParams( new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
SHASHIDHAR MANCHUKONDA
  • 3,302
  • 2
  • 19
  • 40