GridView elements changes their place dynamically when scroll screen

后端 未结 2 1503
野性不改
野性不改 2020-12-14 08:08

i have a gridview layout, and all items are insert very fine,

now if I check on big screen then all work done is fine, because no scrolling is requi

相关标签:
2条回答
  • 2020-12-14 08:53

    You should change your getView method like this.

        public View getView(int position, View convertView, ViewGroup parent){
            // TODO Auto-generated method stub
            View v;
            if(convertView==null)
            {
                LayoutInflater li = getLayoutInflater();
                v = li.inflate(R.layout.icontext, null);
            }else{
                v = convertView;
            }
            TextView tv = (TextView)v.findViewById(R.id.icon_text);
            tv.setText(providers[position]);
            ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
            iv.setImageResource(R.drawable.icon);
    
            return v;
        }
    

    Your problem is that when you use convertView it stores old data form the first records. Convert view is used to avoid layout inflation from resource which costs you time and memory. You should use the old inflated view, but set new data.

    0 讨论(0)
  • 2020-12-14 08:53

    I have just deleted the

    if(convertView==null)
    

    it works

    0 讨论(0)
提交回复
热议问题