2013-06-12 38 views
0

目前我正在使用GalleryView并更改工作正常的图像。GallaryView更改按钮上的图像单击

但我想禁用滑动的GalleryView并更改按钮点击加载的图像。 我如何实现此功能。

我现在的等级是如下提前

public class PopUpWindow extends Activity { 
TextView closebtn; 
Integer[] pics = { 
     R.drawable.account_icon, 
     R.drawable.coffee_icon, 
     R.drawable.help_icon, 
     R.drawable.menu_icon, 

}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setUpDialogProperties(); 
    this.setFinishOnTouchOutside(false); 
    setContentView(R.layout.pop_up_dialog); 
    fetchUI(); 

} 
private void fetchUI(){ 
    closebtn   =   (TextView)findViewById(R.id.okBtn); 
    closeDialog(); 
    Gallery ga = (Gallery)findViewById(R.id.Gallery01); 
     ga.setAdapter(new ImageAdapter(this)); 
     ga.setUnselectedAlpha(0.0f); 
} 

private void closeDialog(){ 
    closebtn.setOnClickListener(new View.OnClickListener() { 

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

     } 
    }); 
} 
private void setUpDialogProperties() { 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setBackgroundDrawableResource(android.R.color.transparent); 
     android.view.WindowManager.LayoutParams lp = getWindow() 
     .getAttributes(); 
     lp.gravity = Gravity.BOTTOM; 
     getWindow().setAttributes(lp); 

    } 
public class ImageAdapter extends BaseAdapter { 

     private Context ctx; 
     int imageBackground; 

     public ImageAdapter(Context c) { 
      ctx = c; 
      TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1); 
      imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1); 
      ta.recycle(); 
     } 

     @Override 
     public int getCount() { 

      return pics.length; 
     } 

     @Override 
     public Object getItem(int arg0) { 

      return arg0; 
     } 

     @Override 
     public long getItemId(int arg0) { 

      return arg0; 
     } 

     @Override 
     public View getView(int arg0, View arg1, ViewGroup arg2) { 
      ImageView iv = new ImageView(ctx); 
      iv.setImageResource(pics[arg0]); 
      iv.setScaleType(ImageView.ScaleType.FIT_CENTER); 
      iv.setLayoutParams(new Gallery.LayoutParams(150,150)); 
      iv.setBackgroundResource(imageBackground); 
      return iv; 
     } 

    } 

感谢

回答

0
case R.id.leftButton: 
     int position = mGallery.getSelectedItemPosition() - 1; 
     if (position < 0) 
      return; 
     mGallery.setSelection(position); 
     break; 
    case R.id.rightButton: 
     position = mGallery.getSelectedItemPosition() + 1; 
     if (position >= mGallery.getCount()) 
      return; 
     mGallery.setSelection(position); 
     break; 

我将设置的onclick你的下一个和上一个按钮

+0

如何在这种情况下禁用画廊刷卡视图? –

+0

你必须重写图库的onTouchListener并始终返回true – Blackbelt

+0

但我在这种情况下使用Base Adapter如何处理? –