johnnybeem
Lurker
Hi all,
I am new to Android development and am trying to set a simple app with a 4x4 grid of TextViews. I've been trying for a few hours now, and can't find the method that returns a "child" View from the GridView. This seems like it should be a pretty simple thing.
Basically, I set up a 4x4 GridView and all of its elements are TextViews. Right now the text in each box of the grid is a single character 'A', 'B', 'C'... up to the first 16 letters. Later in the code, I will need to access the individual views to set properties on them (i.e. background color, text, etc). I have tried all of the following, but none are working properly - the first throws an exception, the second returns null, and the third returns the HashMap for the SimpleAdapter
Object v = adapter.getView(0, lettertext, gridview);
Object v = gridview.getChildAt(0);
Object v = adapter.getItem(0);
Here is some slimmed down code from my onCreate function. Thanks in advance!
I am new to Android development and am trying to set a simple app with a 4x4 grid of TextViews. I've been trying for a few hours now, and can't find the method that returns a "child" View from the GridView. This seems like it should be a pretty simple thing.
Basically, I set up a 4x4 GridView and all of its elements are TextViews. Right now the text in each box of the grid is a single character 'A', 'B', 'C'... up to the first 16 letters. Later in the code, I will need to access the individual views to set properties on them (i.e. background color, text, etc). I have tried all of the following, but none are working properly - the first throws an exception, the second returns null, and the third returns the HashMap for the SimpleAdapter
Object v = adapter.getView(0, lettertext, gridview);
Object v = gridview.getChildAt(0);
Object v = adapter.getItem(0);
Here is some slimmed down code from my onCreate function. Thanks in advance!
Code:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// setup the adapter for showing letters
GridView gridview = (GridView) findViewById(R.id.gridview);
// create the array of letters
ArrayList<HashMap<String,String>> data = new ArrayList<HashMap<String,String>> ();
for (int i=0; i<16; i++) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("lettertext", new Character((char)(65+i)).toString());
data.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.letter,
new String[]{"lettertext"}, new int[]{R.id.lettertext});
gridview.setAdapter(adapter);
//Object v = adapter.getView(0, lettertext, gridview);
//Object v = gridview.getChildAt(0);
//Object v = adapter.getItem(0);
}