开发者

ListView color repetation problem?

I use the following code to set the ListView , the data and buttons are set properly ,when I scroll also there is no problem in data repetition, but when i scroll the color is set for all text fields, how can I resolve it?.

private  class EfficientAdapter extends BaseAdapter {


 public EfficientAdapter(Context context) {
     mInflater = LayoutInflater.from(context);

 }

 public int getCount() {
     return count;
 }

 public Object getItem(int position) {
     return position;
 }

 public long getItemId(int position) {
     return position;
 }

 public View getView(final int position, View convertView, ViewGroup parent) {
     System.gc();
     ViewHolder holder;

     if (convertView == null) {
         convertView = mInflater.inflate(R.layout.albumlist, null);
         holder = new ViewHolder();
         holder.albumName = (TextView) convertView.findViewById(R.id.albumDetails);
         holder.delete=(Button)convertView.findViewById(R.id.deletealbum);
         holder.share=(Button)convertView.findViewById(R.id.shareProject);
         holder.preview=(Button)convertView.findViewById(R.id.prevProject);

         convertView.setTag(holder);
     }
     else {
         holder = (ViewHolder) convertView.getTag();
     }

     holder.albumName.setText(albumData[position][0]);
     if((albumData[position][2].length()==0)){
         holder.albumName.setTextColor(Color.RED);

     }
     holder.delete.setOnClickListener(new View.开发者_开发知识库OnClickListener() {
         public void onClick(View v) {
             // Perform action on click

            .....


     });
     holder.preview.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             ......

         }

     });
     holder.share.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
            ......
     });
     return convertView;

}


holder.albumName.setTextColor(Color.BLACK); //or whatever the original color is

holder.albumName.setText(albumData[position][0]);
 if((albumData[position][2].length()==0)){
     holder.albumName.setTextColor(Color.RED);

 }

you should first reset the original color of the view before you make your move. Listview only recycles the view inside it so you have to do the burden of setting it back to normal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜