1

i just find some solution for an full screen gallery implementation but i cant get the code work. maybe anyone can help me about that.

I need a full screen image switcher without an thumbnail gallery where i can switch between the pictures with swiping with finger.

i got the following error: firstActivity cannot be resolved to a type slide_in_right cannot be resolved or is not a field slide_out_left cannot be resolved or is not a field

i am pretty new to android coding :)

Please help me

package com.example.prog;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ViewSwitcher;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.view.Window;
import android.content.Context;



public class l2_AltInvestActivity extends Activity implements ViewFactory {


ImageSwitcher imageSwitcher;

 Integer[] imageList = {
R.drawable.fr_l1_01,
R.drawable.fr_l1_02,
R.drawable.fr_l1_03,
R.drawable.fr_l1_04,
R.drawable.fr_l1_05
};

int curIndex=0;
int downX, upX;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mmenutest);

    imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
    imageSwitcher.setFactory(this);
    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
    imageSwitcher.setImageResource(imageList[curIndex]);
    imageSwitcher.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                downX = (int) event.getX();
                Log.i("event.getX()", " downX " + downX);
                return true;
            }
            else if (event.getAction() == MotionEvent.ACTION_UP) {
                upX = (int) event.getX();
                Log.i("event.getX()", " upX " + downX); 

                if (upX - downX > 100) {
                    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(firstActivity.this,android.R.anim.slide_in_left));
                    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(firstActivity.this,android.R.anim.slide_out_right));
                    //curIndex  current image index in array viewed by user
                    curIndex--;
                    if (curIndex < 0) {
                        curIndex = 5; //maximum
                    }

                    //imageList :-image list array
                    imageSwitcher.setImageResource(imageList[curIndex]);
                    //GalleryActivity.this.setTitle(curIndex);
                }
                else if (downX -upX > -100) {
                    curIndex++;
                    if (curIndex > 4) {
                        curIndex = 0;
                    }
                    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_in_right));
                    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_out_left));
                    imageSwitcher.setImageResource(imageList[curIndex]);
                    //GalleryActivity.this.setTitle(curIndex);
                }
            return true;
            }
        return false;
        }
    });
} //END onCreate

@Override
public View makeView() {
    ImageView i = new ImageView(this);
    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    i.setBackgroundColor(0xFF000000);
    return i;   
} //END makeView

 } // END Class

1 Answers1

1

Use Current Activity Context to access resources instead of Any other activity as in current code you are trying to access Animation resources by passing firstActivity.this .

imageSwitcher.setInAnimation(AnimationUtils.
        loadAnimation(l2_AltInvestActivity.this,android.R.anim.slide_in_left));
imageSwitcher.setOutAnimation(AnimationUtils.
        loadAnimation(l2_AltInvestActivity.this,android.R.anim.slide_out_right));

use l2_AltInvestActivity.this instead of firstActivity.this

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • thanks, this helps me a lot. but do you have an idear about the slite_out anymation ? slide_in_right slide_out_left – user1966046 Jan 12 '13 at 15:41
  • @user1966046 : if this answer solve your current issue then mark it answer and for any other problem it's good if u make an new question to get good and quick answer – ρяσѕρєя K Jan 12 '13 at 15:46
  • @user1966046 : can i known what is your second issue you are facing currently – ρяσѕρєя K Jan 12 '13 at 15:50
  • i like to get the two slide in animation, which are missing i think. how can i do this, anything would be very nice android.R.anim.slide_in_right android.R.anim.slide_out_left – user1966046 Jan 12 '13 at 15:55
  • ok i opend a new question. in addition i like to have an progress bar under the imageswitcher, would be nice if you could help as well. http://stackoverflow.com/questions/14295227/missing-animation-in-r-anim-and-progressbar-in-imageswitcher – user1966046 Jan 12 '13 at 16:19
  • @user1966046 : friend i saw it and already upvoted your question to get good response – ρяσѕρєя K Jan 12 '13 at 16:21