GridView 예제


텍스트를 그리드에 그리기

public class MyAdapter extends BaseAdapter {


private Context context;
private String[] texts = {“aaa”, “bbb”, “ccc”, “ddd”, “eee”, “fff”, “eee”, “hhh”, “iii”};
 
public MyAdapter(Context context) {
    this.context = context;
}
 
public int getCount() {
    return 9;
}
 
public Object getItem(int position) {
    return null;
}
 
public long getItemId(int position) {
    return 0;
}
 
public View getView(int position, View convertView, ViewGroup parent) {
    TextView tv;
    if (convertView == null) {
        tv = new TextView(context);
        tv.setLayoutParams(new GridView.LayoutParams(85, 85));
    }
    else {
        tv = (TextView) convertView;
    }
 
    tv.setText(texts[position]);
    return tv;
}

http://developer.android.com/guide/tutorials/views/hello-gridview.html

댓글 남기기