我已经制作了网格视图,我必须在其中选择多个项目。但我不想要长按功能。我只希望单击即可选择多个项目。网格视图位于片段下。
这是我的片段类:
public class FragmentOrder extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//View view = inflater.inflate(R.layout.g, null);
View view = inflater.inflate(R.layout.gridview,null);
final GridView listView = (GridView) view.findViewById(R.id.mainGrid);
listView.setAdapter(new OrderGridViewAdapter(MainActivity.this));
//int setSelected = 0;
listView.setSelected(true);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
return view;
}
}
这是我的适配器类:
public class OrderGridViewAdapter extends BaseAdapter{
private Context MContext;
public OrderGridViewAdapter(Context C){
MContext = C;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View myView;
LayoutInflater inflater = (LayoutInflater)MContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myView = inflater.inflate(R.layout.grid_items_ontap, null);
// Add The Image!!!
ImageView iv = (ImageView)myView.findViewById(R.id.grid_item_image_OnTap);
iv.setImageResource(mThumbIds[position]);
// Add The Text!!!
TextView tv = (TextView)myView.findViewById(R.id.grid_item_text_onTap);
tv.setText(names[position] );
return myView;
}
private Integer[] mThumbIds = {
R.drawable.car, R.drawable.car,
R.drawable.car, R.drawable.car,
R.drawable.car,R.drawable.car,R.drawable.car,R.drawable.car, R.drawable.car,
R.drawable.car, R.drawable.car,
R.drawable.car,R.drawable.car,R.drawable.car
};
private String[] names={"ab","cd","ef","gh","ij","kl","mn","","","","","","",""};
}
任何建议将不胜感激。谢谢。