BaseAdapter를 확장하는 사용자 지정 어댑터를 구현하는 갤러리가 있습니다. 일부 항목의 경우 해당 항목을 클릭 할 수 없도록 비활성화해야합니다.갤러리 항목을 사용 중지하는 방법은 무엇인가요?
isEnabled (int) 메서드를 재정의하면 작동하지 않습니다. 나는 여전히 사용할 수없는 항목을 클릭 할 수 있으며 갤러리는이 항목을 그 안의 가운데에 배치합니다.
아이디어가 있으십니까?
BaseAdapter를 확장하는 사용자 지정 어댑터를 구현하는 갤러리가 있습니다. 일부 항목의 경우 해당 항목을 클릭 할 수 없도록 비활성화해야합니다.갤러리 항목을 사용 중지하는 방법은 무엇인가요?
isEnabled (int) 메서드를 재정의하면 작동하지 않습니다. 나는 여전히 사용할 수없는 항목을 클릭 할 수 있으며 갤러리는이 항목을 그 안의 가운데에 배치합니다.
아이디어가 있으십니까?
이 다음은
public boolean onSingleTapUp(MotionEvent e) {
if (mDownTouchPosition >= 0) {
// An item tap should make it selected, so scroll to this child.
scrollToChild(mDownTouchPosition - mFirstPosition);
// Also pass the click so the client knows, if it wants to.
if (mShouldCallbackOnUnselectedItemClick || mDownTouchPosition == mSelectedPosition) {
performItemClick(mDownTouchView, mDownTouchPosition, mAdapter
.getItemId(mDownTouchPosition));
}
return true;
}
return false;
}
당신이 볼 수 있듯이 갤러리 위젯의 관련 소스 코드, 거기에 클릭을 수행하기 전에 탭 하위 항목으로 갤러리 스크롤됩니다. 정말 항목을 비활성화 할 수있는 유일한 방법은 Gallery
을 확장하고 onSingleTapUp(MotionEvent e)
을 덮어 쓰는 것입니다.
@Override
public boolean onSingleTapUp(MotionEvent e) {
int itemPosition = pointToPosition((int) e.getX(), (int) e.getY());
if (item at itemPosition is disabled) {
// Do nothing.
return true;
}
return super.onSingleTapUp(e);
}
알려주세요.
특정 위치에 대한 클릭 이벤트를 처리 할 수있는 코드를 사용해보십시오. 또한 특정 항목을 비활성화 할 수 있습니다.
public class SplashActivity extends Activity{
private Activity _activity;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Gallery g = new Gallery(this);
g.setAdapter(new ImageAdapter(this));
setContentView(g);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.menu1,
R.drawable.menu2,
R.drawable.menu3,
R.drawable.menu4,
R.drawable.menu1,
R.drawable.menu2,
R.drawable.menu3,
R.drawable.menu4
};
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
if(position!=0){
i.setEnabled(false);
i.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(SplashActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
return i;
}
}
}
이것을 사용해 보셨습니까 ??? –
try setFocusable (false); 수도 있습니다 – ingsaurabh
이것은 또한 작동하지 않습니다. onItemClick 이벤트가 호출됩니다. –
일부 코드를 붙여 넣거나이 방에 올 수 있습니까? http://chat.stackoverflow.com/rooms/10629/agarwal –