How to use gallery.getItemAtPosition(position) to get the view object like bel开发者_开发知识库ow.
Object obj = gallery.getItemAtPosition(position);
View v = (View)object;
ImageView imgview = (ImageView)v.findViewById(R.id.imageId);
But if i use like that it is giving class cast exception.
Typically I use it like this, on select event
public void onItemSelected(AdapterView arg0, View v, int position, long arg3) { //here v is the imageview which is selected. //In your case u might want something like this. ImageView img = (ImageView) arg0.getChildAt(position); //To get the view }
That source code does not make much sense, or vital information is missing. Have you connected a SpinnerAdapter to the gallery? What type of objects do the adapter return?
I assume all objects in the gallery are of the same type?
Object obj = gallery.getItemAtPosition(position);
You should cast to this object type directly.
TheType obj = (TheType)gallery.getItemAtPosition(position);
精彩评论