다음 코드를 사용하여 gridview (http://developer.android.com/resources/tutorials/views/hello-gridview.html에서 약간 수정)로 작업하고 있습니다. onClickListener 및 onClick() 메소드를 touch 리 테인 (touchlistener)과 onTouch() 메소드로 대체하고자합니다. 그리드 뷰의 엘리먼트를 터치하면 엘리먼트의 이미지가 바뀌고 같은 엘리먼트에 더블 터치가 걸리게됩니다. 원래의 상태로 되돌아갑니다.Android 초보자 : android gridview의 터치 이벤트
어떻게하면됩니까? 나는 이것을 할 수있는 코드를 얻을 수 없다. clicklistener는 어느 정도 작동하지만 터치가 아닙니다. 도와주세요.
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if(position==0)
{
//do this
}
else
{
//do this
}
}
});
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
}
안녕 AJ를, 이동, 또는 키 여기에 밀리지 않은 상태였다 나는 물건을 땡그랑 소리로 말하고 싶다. 나는 그리드에서 그 위치를 얻고 싶고 그 이미지를 바꾸고 싶다. 내가 어떻게 할 수 있니? 지금 당장 어떤 유혹이 있니? 감사 Faheem –