problem about gridview and baseadapter? Pls help

Posted by flybirdtt on Stack Overflow See other posts from Stack Overflow or by flybirdtt
Published on 2010-05-20T13:50:14Z Indexed on 2010/05/20 13:50 UTC
Read the original article Hit count: 348

Filed under:

I need a gridview to place 9 items. And i write a custom baseadapter.

But find a problem about the position in the getView method.it looks like this gridview miss the 7th item.The code like this:`

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutDTO lDto = menuHashtable.get(Integer.toString(position));
    ViewHolder vHolder = new ViewHolder();
    if (lDto != null) {
            String titleString = lDto.getTitle();
            Log.v("title...........", titleString + "  " + Integer.toString(position) );
            Bitmap iconBitmap = lDto.getIcon();
            convertView = mInflater.inflate(R.layout.custombutton, null);
            vHolder.icon = (ImageView) convertView
                    .findViewById(R.id.imageicon);
            vHolder.icon.setImageBitmap(iconBitmap);
            vHolder.text = (TextView) convertView
                    .findViewById(R.id.icontitle);
            int index = titleString.indexOf("\u0026");
            if (index != -1) {
                String title1 = titleString.substring(0, index + 1).trim();
                String title2 = titleString.substring(index + 1,
                        titleString.length()).trim();
                vHolder.text.setLines(2);
                String newtitle = title1 + "\n" + title2;
                vHolder.text.setText(newtitle);
            } else {
                vHolder.text.setLines(2);
                String newtitle = titleString + "\n" + " ";
                vHolder.text.setText(newtitle);
            }
            convertView.setTag(vHolder);
    }

    return convertView;
}`

The log show this:

05-20 21:37:16.066: VERBOSE/title...........(158): Dining 0 05-20 21:37:16.105: VERBOSE/title...........(158): Dining 0 05-20 21:37:16.125: VERBOSE/title...........(158): Dining 0

05-20 21:37:16.135: VERBOSE/title...........(158): Dining 0

05-20 21:37:16.166: VERBOSE/title...........(158): Dining 0

05-20 21:37:16.185: VERBOSE/title...........(158): Entertainment 1

05-20 21:37:16.195: VERBOSE/title...........(158): Shopping 2

05-20 21:37:16.195: VERBOSE/title...........(158): Fashion 3

05-20 21:37:16.205: VERBOSE/title...........(158): Health & Beauty 4

05-20 21:37:16.215: VERBOSE/title...........(158): Supermarkets 5

05-20 21:37:16.226: VERBOSE/title...........(158): Auto Services 6

05-20 21:37:16.236: VERBOSE/title...........(158): Travel & Accommodation 8

05-20 21:37:16.316: VERBOSE/title...........(158): Dining 0

05-20 21:37:16.326: VERBOSE/title...........(158): Dining 0

05-20 21:37:16.336: VERBOSE/title...........(158): Dining 0

05-20 21:37:16.345: VERBOSE/title...........(158): Dining 0

© Stack Overflow or respective owner

Related posts about android