如何在网格中设置备用单元格颜色 [英] How set Alternate Cell Color in a Grid

查看:129
本文介绍了如何在网格中设置备用单元格颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么设置网格中的备用电池颜色? 我发现了很多问题/教程 有关如何设置行的颜色,但没有 有关细胞的颜色。 在此先感谢

How set alternate cell Color in a grid ? I've found a lot of questions/tutorials about how to set row colors but nothing about cells' color. Thanks in advance

推荐答案

一个进步,它的工作原理

A step forward and it works

public class ListViewA extends Activity {
GridView MyGrid;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MyGrid = (GridView) findViewById(R.id.gridview);
    MyGrid.setAdapter(new ImageAdapter(this));
}

public class ImageAdapter extends BaseAdapter {
    Context MyContext;

    public ImageAdapter(Context _MyContext) {
        MyContext = _MyContext;
    }

    @Override
    public int getCount() {
        return 9;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if (convertView == null) {

            LayoutInflater li = getLayoutInflater();
            view = li.inflate(R.layout.main, null);
        }

        if (position % 2 == 0)
            view.setBackgroundColor(0x30FF0000);
        else
            view.setBackgroundColor(0x300000FF);
        return view;

    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }
}

}

这篇关于如何在网格中设置备用单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆