我有一个带有ImageView项目的GridView,我想在某个位置以编程方式选择一个项目。我觉得这很容易,但...... setSelection
什么都不做,为什么?
public class Test extends Activity {
public void onCreate (final Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
GridView gridView = new GridView (this);
gridView.setNumColumns (4);
gridView.setHorizontalSpacing (16);
gridView.setVerticalSpacing (16);
setContentView (gridView);
gridView.setAdapter (new BaseAdapter () {
public int getCount () {
return 12;
}
public Object getItem (int position) {
return position;
}
public long getItemId (int position) {
return position;
}
public View getView (int position, View convertView, ViewGroup parent) {
ImageView view = (ImageView) convertView;
if (view == null) {
view = new ImageView (Test.this);
view.setImageResource (R.drawable.image);
}
return view;
}
});
gridView.setSelection (3); // ?? does nothing
}
}