2012-06-11 15 views
2

我试图根据从远程服务器上的数据库接收到的标志来更改行的背景颜色。基于自定义适配器中的条件在特定行上更改背景

在我的代码中,我创建了一个名为disable的ArrayList,它包含所有被标记的位置。我想将禁用列表中的内容与ListView中的位置进行匹配。 我已经研究了几个帖子,没有一个明确表明如何做到这一点。我将所找到的内容拼凑在一起,并将其放在下面的自定义适配器中。

从我理解的公众int getItemViewType(int位置)可以根据条件选择特定的行并更改它的属性。满足此条件时如何更改背景?我的程序中的getItemViewType(int position)中的代码不起作用,但您可以看到我正在尝试执行的操作。

问题1:我需要制作两个xml布局文件吗?一个用于普通视图和另一个禁用视图? 问题2:你知道任何已经实现了我可以遵循的例子吗?

package com.convention.notification.app; 

import java.util.List; 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.text.Html; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 

public class NewsRowAdapter extends ArrayAdapter<Item> { 

    private Activity activity; 
    private List<Item> items; 
    private Item objBean; 
    private int row; 
    private List<Integer> disable; 
    View view ; 


    public NewsRowAdapter(Activity act, int resource, List<Item> arrayList, List<Integer> disableList) { 
     super(act, resource, arrayList); 
     this.activity = act; 
     this.row = resource; 
     this.items = arrayList; 
     this.disable=disableList; 

     System.out.println("results of delete list a:"+disable.toString()); 


    } 

    public int getCount(){ 
     return items.size(); 
    } 

    public Item getItem(int position){ 
     return null; 
     } 

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

    @Override 
    public int getViewTypeCount() { 
     return 2; 


     } 

    @Override 
    public int getItemViewType(int position) { 

     for (int s: disable){ 


      if (s == position){ 

      // view.setBackgroundColor(Color.YELLOW); 

      } 


     } 
     return position; 

    } 


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


     ViewHolder holder; 
     if (view == null) { 
      //ViewHolder is a custom class that gets TextViews by name 
      holder = new ViewHolder(); 

      LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view = inflater.inflate(row, null); 


      // holder.txtViewDescription = (TextView) convertView.findViewById(R.id.txtViewDescription); 


      /* setTag Sets the tag associated with this view. A tag can be used to 
      * mark a view in its hierarchy and does not have to be unique 
      * within the hierarchy. Tags can also be used to store data within 
      * a view without resorting to another data structure. 

*/ 
     view.setTag(holder); 
     } else { 



      //the Object stored in this view as a tag 
      holder = (ViewHolder) view.getTag(); 
     } 

     if ((items == null) || ((position + 1) > items.size())){ 

      return view; 
     } 

     objBean = items.get(position); 


     holder.tv_event_name = (TextView) view.findViewById(R.id.tv_event_name); 
     holder.tv_event_date = (TextView) view.findViewById(R.id.tv_event_date); 
     holder.tv_event_start = (TextView) view.findViewById(R.id.tv_event_start); 
     holder.tv_event_end = (TextView) view.findViewById(R.id.tv_event_end); 
     holder.tv_event_location = (TextView) view.findViewById(R.id.tv_event_location); 


     if (holder.tv_event_name != null && null != objBean.getName() 
       && objBean.getName().trim().length() > 0) { 
      holder.tv_event_name.setText(Html.fromHtml(objBean.getName())); 

     } 
     if (holder.tv_event_date != null && null != objBean.getDate() 
       && objBean.getDate().trim().length() > 0) { 
      holder.tv_event_date.setText(Html.fromHtml(objBean.getDate())); 
     } 
     if (holder.tv_event_start != null && null != objBean.getStartTime() 
       && objBean.getStartTime().trim().length() > 0) { 
      holder.tv_event_start.setText(Html.fromHtml(objBean.getStartTime())); 
     } 
     if (holder.tv_event_end != null && null != objBean.getEndTime() 
       && objBean.getEndTime().trim().length() > 0) { 
      holder.tv_event_end.setText(Html.fromHtml(objBean.getEndTime())); 
     } 
     if (holder.tv_event_location != null && null != objBean.getLocation() 
       && objBean.getLocation().trim().length() > 0) { 
      holder.tv_event_location.setText(Html.fromHtml(objBean.getLocation())); 

     } 


     return view; 
    } 

    public class ViewHolder { 
     public TextView 
     tv_event_name, 
     tv_event_date, 
     tv_event_start, 
     tv_event_end, 
     tv_event_location 
     /*tv_event_delete_flag*/; 


    } 


} 

的logcat:

06-11 00:06:43.133: D/dalvikvm(60): GC_EXPLICIT freed 230K, 45% free 4939K/8839K, external 3511K/3903K, paused 81ms 
06-11 00:06:43.133: I/installd(34): unlink /data/dalvik-cache/[email protected]@com.convention.notif[email protected] 
06-11 00:06:43.133: D/AndroidRuntime(528): Shutting down VM 
06-11 00:06:43.173: D/dalvikvm(528): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 1ms+0ms 
06-11 00:06:43.173: D/jdwp(528): Got wake-up signal, bailing out of select 
06-11 00:06:43.173: D/dalvikvm(528): Debugger has detached; object registry had 1 entries 
06-11 00:06:43.203: I/dalvikvm(528): JNI: AttachCurrentThread (from ???.???) 
06-11 00:06:43.203: I/AndroidRuntime(528): NOTE: attach of thread 'Binder Thread #3' failed 
06-11 00:06:43.653: D/AndroidRuntime(542): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<< 
06-11 00:06:43.653: D/AndroidRuntime(542): CheckJNI is ON 
06-11 00:06:44.223: D/AndroidRuntime(542): Calling main entry com.android.commands.am.Am 
06-11 00:06:44.243: I/ActivityManager(60): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.convention.notification.app/.DataView } from pid 542 
06-11 00:06:44.273: I/ActivityManager(60): Start proc com.convention.notification.app for activity com.convention.notification.app/.DataView: pid=550 uid=10042 gids={3003} 
06-11 00:06:44.323: D/AndroidRuntime(542): Shutting down VM 
06-11 00:06:44.323: D/dalvikvm(542): GC_CONCURRENT freed 103K, 69% free 319K/1024K, external 0K/0K, paused 1ms+1ms 
06-11 00:06:44.334: D/dalvikvm(542): Debugger has detached; object registry had 1 entries 
06-11 00:06:45.503: I/ActivityManager(60): Displayed com.convention.notification.app/.DataView: +1s233ms 
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :1 
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :6 
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :14 
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :15 
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :18 
06-11 00:06:47.163: I/System.out(550): results of delete list :[1, 6, 14, 15, 18] 
06-11 00:06:47.163: I/System.out(550): results of delete list in Adapeter:[1, 6, 14, 15, 18] 
06-11 00:06:47.173: I/System.out(550): set adapaer to list view called; 
06-11 00:06:50.693: D/dalvikvm(237): GC_EXPLICIT freed 8K, 51% free 2725K/5511K, external 1625K/2137K, paused 61ms 
06-11 00:06:55.783: D/dalvikvm(264): GC_EXPLICIT freed 17K, 52% free 2778K/5703K, external 1625K/2137K, paused 98ms 
06-11 00:07:05.163: D/dalvikvm(308): GC_EXPLICIT freed 15K, 49% free 3363K/6535K, external 1625K/2137K, paused 43ms 
06-11 00:07:10.284: D/dalvikvm(361): GC_EXPLICIT freed 15K, 48% free 3523K/6727K, external 1625K/2137K, paused 102ms 
06-11 00:07:15.303: D/dalvikvm(378): GC_EXPLICIT freed 6K, 51% free 2718K/5511K, external 1625K/2137K, paused 73ms 
06-11 00:07:20.383: D/dalvikvm(201): GC_EXPLICIT freed 21K, 50% free 2995K/5959K, external 1625K/2137K, paused 121ms 
06-11 00:07:25.463: D/dalvikvm(130): GC_EXPLICIT freed 114K, 48% free 3089K/5895K, external 4932K/5608K, paused 124ms 
06-11 00:11:22.113: D/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol 

--------------------------更新------- ---------------------- 我通过删除getItem()方法修复了此异常错误,并且能够在列表中的几个视图上看到黄色背景。

当前问题在while循环中。我试图将我的列表视图与标记的项目进行比较,并仅在标记的项目上放置一个黄色背景。不过,我每四次看到一个黄色背景。这不是我打算做的。你能告诉我该怎么做来修正While循环和/或for循环中的逻辑以获得与正确位置/视图匹配的黄色背景吗?

下面是更新后的代码:

package com.convention.notification.app; 

import java.util.List; 



import android.app.Activity; 
import android.content.Context; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.text.Html; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 

public class NewsRowAdapter extends ArrayAdapter<Item> { 

    private Activity activity; 
    private List<Item> items; 
    private Item objBean; 
    private int row; 
    private List<Integer> disable; 
    View view ; 

    public NewsRowAdapter(Activity act, int resource, List<Item> arrayList, List<Integer> disableList) { 
     super(act, resource, arrayList); 
     this.activity = act; 
     this.row = resource; 
     this.items = arrayList; 
     this.disable=disableList; 

     System.out.println("results of delete list a:"+disable.toString()); 



    } 






      @Override 
      public View getView(final int position, View convertView, ViewGroup parent) { 
       View view = convertView; 
       ViewHolder holder; 
       if (view == null) { 
        LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        view = inflater.inflate(row, null); 



        try{ 
           int j = 0; 
           while (j < items.size()) { 
            for(int k =0;k< disable.size();k++){ 
             if(position == disable.get(k)){ 
              view.setBackgroundColor(Color.YELLOW); 
              System.out.println("background set to yellow at disable "+disable.get(j)); 
System.out.println("background set to yellow at position "+position); 
             } else { 
              view.setBackgroundColor(Color.WHITE); 
      System.out.println("background set to white at position "+position); 

        } 
            } 

            j++; 
           } 
        }catch(IndexOutOfBoundsException e){ 

        System.out.println(" crash"); 
        } 




        //ViewHolder is a custom class that gets TextViews by name: tvName, tvCity, tvBDate, tvGender, tvAge; 
        holder = new ViewHolder(); 

        /* setTag Sets the tag associated with this view. A tag can be used to 
        * mark a view in its hierarchy and does not have to be unique 
        * within the hierarchy. Tags can also be used to store data within 
        * a view without resorting to another data structure. 

     */ 
        view.setTag(holder); 
       } else { 

        //the Object stored in this view as a tag 
        holder = (ViewHolder) view.getTag(); 
       } 

       if ((items == null) || ((position + 1) > items.size())) 
        return view; 

       objBean = items.get(position); 


     holder.tv_event_name = (TextView) view.findViewById(R.id.tv_event_name); 
     holder.tv_event_date = (TextView) view.findViewById(R.id.tv_event_date); 
     holder.tv_event_start = (TextView) view.findViewById(R.id.tv_event_start); 
     holder.tv_event_end = (TextView) view.findViewById(R.id.tv_event_end); 
     holder.tv_event_location = (TextView) view.findViewById(R.id.tv_event_location); 


     if (holder.tv_event_name != null && null != objBean.getName() 
       && objBean.getName().trim().length() > 0) { 
      holder.tv_event_name.setText(Html.fromHtml(objBean.getName())); 

     } 
     if (holder.tv_event_date != null && null != objBean.getDate() 
       && objBean.getDate().trim().length() > 0) { 
      holder.tv_event_date.setText(Html.fromHtml(objBean.getDate())); 
     } 
     if (holder.tv_event_start != null && null != objBean.getStartTime() 
       && objBean.getStartTime().trim().length() > 0) { 
      holder.tv_event_start.setText(Html.fromHtml(objBean.getStartTime())); 
     } 
     if (holder.tv_event_end != null && null != objBean.getEndTime() 
       && objBean.getEndTime().trim().length() > 0) { 
      holder.tv_event_end.setText(Html.fromHtml(objBean.getEndTime())); 
     } 
     if (holder.tv_event_location != null && null != objBean.getLocation() 
       && objBean.getLocation().trim().length() > 0) { 
      holder.tv_event_location.setText(Html.fromHtml(objBean.getLocation())); 

     } 


     return view; 
    } 

    public class ViewHolder { 
     public TextView 
     tv_event_name, 
     tv_event_date, 
     tv_event_start, 
     tv_event_end, 
     tv_event_location 
     /*tv_event_delete_flag*/; 


    } 


} 

的logcat:

06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :1 
06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :6 
06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :14 
06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :15 
06-11 10:54:45.073: I/System.out(1692): item disalbed is at postion :18 
06-11 10:54:45.073: I/System.out(1692): results of delete list :[1, 6, 14, 15, 18] 
06-11 10:54:45.073: I/System.out(1692): results of delete list a:[1, 6, 14, 15, 18] 
06-11 10:54:45.073: I/System.out(1692): set adapaer to list view called; 
06-11 10:54:45.183: I/System.out(1692): background set to white at position 0 

06-11 10:54:45.393: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0 
06-11 10:54:45.573: I/System.out(1692): background set to yellow at disable list 1 
06-11 10:54:45.573: I/System.out(1692): background set to yellow at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to yellow at disable list 6 
06-11 10:54:45.573: I/System.out(1692): background set to yellow at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.573: I/System.out(1692): background set to yellow at disable list 14 
06-11 10:54:45.573: I/System.out(1692): background set to yellow at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to yellow at disable list 15 
06-11 10:54:45.583: I/System.out(1692): background set to yellow at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to yellow at disable list 18 
06-11 10:54:45.583: I/System.out(1692): background set to yellow at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1 
06-11 10:54:45.593: I/System.out(1692): crash 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2 
06-11 10:54:45.623: I/Sys....3,4,.... 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to yellow at disable list 1 
06-11 10:54:46.283: I/System.out(1692): background set to yellow at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to yellow at disable list 6 
06-11 10:54:46.283: I/System.out(1692): background set to yellow at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to yellow at disable list 14 
06-11 10:54:46.283: I/System.out(1692): background set to yellow at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.293: I/System.out(1692): background set to yellow at disable list 15 
06-11 10:54:46.293: I/System.out(1692): background set to yellow at position 6 
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to yellow at disable list 18 
06-11 10:54:46.303: I/System.out(1692): background set to yellow at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6 
06-11 10:54:46.303: I/System.out(1692): crash 
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7 
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7 
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7 
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7 
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7 
06-11 10:54:46.353: I/System.out(...... 

感谢您的帮助!

回答

0

通过在视图中查找其ID来获取整个想要更改背景的行。现在设置了您所选择的backgound ...

获取进一步的帮助从这个链接..:

Changing background color of ListView items on Android

+0

不幸的是,@Awais塔里克您张贴在链接的例子是已经被点击的项目并且该信息被发送到适配器。我需要的是将一个标志列表与从数据库生成的大量项目进行比较。我想通过更改背景来指示此标志。使用适配器的帖子中的一个例子是不完整的,并且不清楚curSelected是如何实现的。我已经在这个几天了,我想要帮助这个计划。 – Leoa

+0

我能够让背景颜色改变,但逻辑关闭[link](http://leobee.com/android/push/so/flag.jpg)它没有使用禁用列表的值并比较它到视图的位置。我怎么把这些放在一起?我在我的原始问题的底部发布了我的代码的更新版本。 – Leoa

相关问题