我有一个带有 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
}
}