我可以在网格中的视图中一一选择字母。但是我该怎么做才能使其看起来像这样?
我想获取在此处浏览的所有教科书中的信息,直到触摸屏幕为止。然后我要杀死那些选定的textview
我到了某个点。
请帮助我
GridView gridView;
MyCustomAdapter myAdapter;
ArrayList<GridObject> myObjects;
static final String[] numbers = new String[] { "A", "B", "C", "D", "E",
"F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myObjects = new ArrayList<GridObject>();
for (String s : numbers) {
myObjects.add(new GridObject(s, 0));
}
gridView = (GridView) findViewById(R.id.gridView1);
myAdapter = new MyCustomAdapter(this);
gridView.setAdapter(myAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
myObjects.get(position).setState(1);
myAdapter.notifyDataSetChanged();
}
});
}
static class ViewHolder {
TextView text;
}
private class MyCustomAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public MyCustomAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
GridObject object = myObjects.get(position);
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(object.getName());
if (object.getState() == 1) {
holder.text.setBackgroundColor(Color.GREEN);
} else {
holder.text.setBackgroundColor(Color.BLUE);
}
return convertView;
}
@Override
public int getCount() {
return myObjects.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
}