我有GridView
来自drawable
的图片。当我点击任何图像时,它总是从数组中打开第一个元素,而不是确定的点击元素。我的代码有什么问题?你有什么想法吗?谢谢!
单击任何图像时发生了什么:
private GridView.OnItemClickListener gridviewOnItemClickListener = new GridView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),
FullImageActivity.class);
i.putExtra("id", position);
startActivity(i);
}
};
有我的FullImageActivity
public class FullImageActivity extends AppCompatActivity {
ImageView imageView;
ViewPager viewPager;
SlideImageAdapter adapter;
MainActivity mainActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
getMyIntent();
}
private void getMyIntent(){
Intent intent = getIntent();
int position = intent.getExtras().getInt("id");
viewPager = (ViewPager) findViewById(R.id.myViewPager);
adapter = new SlideImageAdapter(this, position);
viewPager.setAdapter(adapter);
}
有我的SlideImageAdapter
public class SlideImageAdapter extends PagerAdapter {
private Context mContext;
private LayoutInflater layoutInflater;
int number;
public SlideImageAdapter(Context mContext, int number){
this.mContext = mContext;
this.number = number;
}
@Override
public int getCount() {
return MainActivity.mThumbIds.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(LinearLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflater.inflate(R.layout.swipe_layout, container, false);
ImageView imageView = (ImageView) item_view.findViewById(R.id.full_image_view);
imageView.setImageResource(MainActivity.mThumbIds[position]);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
答案 0 :(得分:2)
呼叫:
var sel = document.getElementById(name);
之后:
UseAppServiceAuthentication
您正在获取该位置,并将其发送到适配器,但您没有使用它。设置适配器后,您可以手动设置位置。