2012-04-19 12 views
0

こんにちは私は2つの異なるイメージ配列をギャラリーに渡す必要があります。 1アレイ13画像と2アレイ16画像を持っています。1ボタンをクリックする必要があります 1アレイに関連する画像をギャラリーに1つのアクティビティにします。2ボタンをクリックすると、2つの配列が1つのアクティビティになります。私は1つのボタンをクリックするとこれを使用していくつかの方法を使用して1つの配列関連の画像を表示し、13のすべての画像がスクロールされますが、私の問題は2ボタンをクリックすると、スクロール、14画像が以降スクロールいない、唯一の13の画像は、私はこのコードで間違っていたdisplyed.whereいずれかが同じギャラリーを使って異なるサイズの配列をアンドロイドの1つのアクティビティに追加する方法

GalleryActivityの.classファイル....私を提案してください:この機能で

public class GalleryActivity extends Activity implements 
     AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory{ 
    private TextSwitcher mSwitcher; 
    Gallery g; 
    static int nextbtn = 0; 
    static int prebtn = 0; 
    ImageAdapter iadapter; 
    int galpos; 
    int countk1=0; 
    public int ht; 
    public int wt; 

    public static int motiongal = 3000; 
    LinearLayout l1; 

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

     DisplayMetrics displaymetrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
     ht = displaymetrics.heightPixels; 
     wt = displaymetrics.widthPixels; 
     l1=(LinearLayout)findViewById(R.id.linear); 
     mSwitcher = (TextSwitcher) findViewById(R.id.switcher); 
     mSwitcher.setFactory(this); 
     mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, 
      android.R.anim.fade_in)); 
     mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, 
      android.R.anim.fade_out)); 
     mSwitcher.startLayoutAnimation(); 
     try 
     { 
      g = (Gallery) findViewById(R.id.gallery); 
      g.setAdapter(new ImageAdapter(this)); 
      g.setHorizontalScrollBarEnabled(false); 
      Bundle bundle = getIntent().getExtras(); 
      galpos = bundle.getInt("GALPOS"); 

      g.setSelection(galpos); 
      g.setAnimationDuration(motiongal); 

      countk1 = getIntent().getIntExtra("k", 0); 
     } catch(Exception e){ 
     } 
     g.setOnItemSelectedListener(this); 
     ImageButton nextButton = (ImageButton) findViewById(R.id.nextimage); 
     nextButton.setOnClickListener(nextButtonOnClick); 

     ImageButton preButton = (ImageButton) findViewById(R.id.preimage); 
     preButton.setOnClickListener(preButtonOnClick); 
    } 

    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { 
     mSwitcher.setText(mTextNames[position]); 
     nextbtn = position; 
    } 

    public OnClickListener nextButtonOnClick = new OnClickListener(){ 
     public void onClick(View v) { 
      if(nextbtn < (mTextNames.length-1)) 
      { 
       try 
       { 
        mSwitcher.setText(mTextNames[nextbtn+1]); 
        mSwitcher.startLayoutAnimation(); 
        mSwitcher.getDrawingTime(); 
        g.setSelection(nextbtn+1); 
        Thread.sleep(300); 
        g.scheduleLayoutAnimation(); 
        g.startLayoutAnimation(); 
        Thread.sleep(300); 
        g.setAnimationDuration(motiongal); 
       } 
       catch(Exception e) 
       {} 
      }else 
      { 
       try 
       { 
        mSwitcher.setText(mTextNames[0]); 
        mSwitcher.startLayoutAnimation(); 
        mSwitcher.getDrawingTime(); 
        g.setSelection(0); 
        Thread.sleep(300); 
        g.scheduleLayoutAnimation(); 
        g.startLayoutAnimation(); 
        Thread.sleep(300); 
        g.setAnimationDuration(motiongal); 
       } 
       catch(Exception e) 
       {} 
      } 
     } 
    }; 

    public OnClickListener preButtonOnClick = new OnClickListener(){ 
     public void onClick(View v) { 
      if(nextbtn > 0) 
      { 
       try 
       { 
        mSwitcher.startLayoutAnimation(); 
        mSwitcher.getDrawingTime(); 
        g.setSelection(nextbtn-1); 
        Thread.sleep(300); 
        g.scheduleLayoutAnimation(); 
        g.startLayoutAnimation(); 
        Thread.sleep(300); 
        g.setAnimationDuration(motiongal); 
       } 
       catch(Exception e) 
       {} 
      }else 
      { 
       try 
       { 
        mSwitcher.setText(mTextNames[mTextNames.length-1]); 
        mSwitcher.startLayoutAnimation(); 
        mSwitcher.getDrawingTime(); 
        g.setSelection(mTextNames.length-1); 
        Thread.sleep(300); 
        g.scheduleLayoutAnimation(); 
        g.startLayoutAnimation(); 
        Thread.sleep(300); 
        g.setAnimationDuration(motiongal); 
       } 
       catch(Exception e) 
       {} 
      } 
     } 
    }; 

    public void onNothingSelected(AdapterView<?> parent) { 
    } 

    public View makeView() { 
     TextView i = new TextView(this); 
     i.setTextSize(18); 
     i.setGravity(1); 
     return i; 
    } 

    public class ImageAdapter extends BaseAdapter { 
     public ImageAdapter(Context c) { 
      mContext = c; 
     } 

     public int getView() { 
      // TODO Auto-generated method stub 
      return 0; 
     } 

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

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

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

     public View getView(int position, View convertView, ViewGroup parent) { 
      ImageView i = new ImageView(mContext); 
      if(countk1==1) 
      { 
       i.setImageResource(mPhotos.get(position)); 
      } 
      if(countk1==2) 
      { 
       i.setImageResource(mPhotos1.get(position)); 
      } 

      i.setScaleType(ImageView.ScaleType.FIT_XY); 
      if(wt >= 480){ 
       if(wt == 480 && ht > 320) { 
        i.setLayoutParams(new Gallery.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
       } else { 
        i.setLayoutParams(new Gallery.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
       } 
      }else{ 
       i.setLayoutParams(new Gallery.LayoutParams(
       LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
      } 
      return i; 
     } 

     private Context mContext; 
    } 

    private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){ 
      return e2.getX() > e1.getX(); 
     } 

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ 
     int kEvent; 
     if(isScrollingLeft(e1, e2)){ //Check if scrolling left 
      kEvent = KeyEvent.KEYCODE_DPAD_LEFT; 
     } 
     else{ //Otherwise scrolling right 
      kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; 
     } 
     onKeyDown(kEvent, null); 
     return true; 
    } 

    private Integer[] mImageIds = { 
     R.drawable.bokstavslottet01, 
     R.drawable.bokstavslottet02, 
     R.drawable.bokstavslottet03, 
     R.drawable.bokstavslottet04, 
     R.drawable.bokstavslottet05, 
     R.drawable.bokstavslottet06, 
     R.drawable.bokstavslottet07, 
     R.drawable.bokstavslottet08, 
     R.drawable.bokstavslottet09, 
     R.drawable.bokstavslottet10, 
     R.drawable.bokstavslottet11, 
     R.drawable.bokstavslottet12, 
     R.drawable.bokstavslottet13 
    }; 
    private Integer[] mImageIdsf = { 
     R.drawable.f1, 
     R.drawable.f2, 
     R.drawable.f3, 
     R.drawable.f4, 
     R.drawable.f5, 
     R.drawable.f6, 
     R.drawable.f7, 
     R.drawable.f8, 
     R.drawable.f9, 
     R.drawable.f10, 
     R.drawable.f11, 
     R.drawable.f12, 
     R.drawable.f13, 
     R.drawable.f14, 
     R.drawable.f15, 
     R.drawable.f16, 
    }; 
    private static String[] mTextNames = { 
     "BOOKSTOVEN1", "BOOKSTOVEN2", "BOOKSTOVEN3", "BOOKSTOVEN4", "BOOKSTOVEN5", "BOOKSTOVEN6", "BOOKSTOVEN7", "BOOKSTOVEN8", "BOOKSTOVEN9", "BOOKSTOVEN10", "BOOKSTOVEN11", "BOOKSTOVEN12", "BOOKSTOVEN13"}; 

    private ArrayList<Integer> mPhotos = new ArrayList<Integer>(Arrays.asList(mImageIds)); 
    private ArrayList<Integer> mPhotos1 = new ArrayList<Integer>(Arrays.asList(mImageIdsf)); 
} 

答えて

0
public int getCount() { 
    return mPhotos1.size(); 
} 

ます2番目のリストが表示されている場合は2番目のリストのカウントを取らなければならない 最初のリストが表示されている場合は最初のリスト

+0

thaks。私もこのようにしてみました。関連画像はすべて表示されています。しかし、mphotos関連の画像を表示すると、その時間に13nthの画像が来るとエラーが表示されます。 – user1105975

関連する問題