Question

In my display adapter ptrelevant I visualize data from a database. I wish the M value of the column relative to the TextView turn, was colored red. How can I do this?

public DisplayAdapter(Context c, ArrayList<String> id,ArrayList<String> ore,ArrayList<String> turno) {
      this.mContext = c;

      this.id = id;
      this.turnoName = turno;
      this.oreName = ore;
   }

   public int getCount() {
      // TODO Auto-generated method stub
      return id.size();
   }

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

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

   public View getView(int pos, View child, ViewGroup parent) {
      Holder mHolder;
      LayoutInflater layoutInflater;
      if (child == null) {
         layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         child = layoutInflater.inflate(R.layout.row, null);
         mHolder = new Holder();
         mHolder.txt_turno = (TextView) child.findViewById(R.id.txt_turno);
         mHolder.txt_ore = (TextView) child.findViewById(R.id.txt_ore);
         mHolder.txt_id = (TextView) child.findViewById(R.id.txt_id);
         child.setTag(mHolder);
      } else {
         mHolder = (Holder) child.getTag();
      }
      mHolder.txt_turno.setText(turnoName.get(pos));
      mHolder.txt_ore.setText(oreName.get(pos));

      return child;
   }

   public class Holder {
      TextView txt_turno;
      TextView txt_ore;
      TextView txt_id;
   }
}
Was it helpful?

Solution

Weird...that works for me: try this :

     mHolder.txt_turno.setText(turnoName.get(pos));
     mHolder.txt_ore.setText(oreName.get(pos));
     mHolder.txt_id.setText(dataName.get(pos));

     String Turno = turnoName.get(pos);

mHolder.txt_turno.setTextColor(Color.WHITE);

if (Turno != null){ 
if (TextUtils.equals(Turno,"M"))
          mHolder.txt_turno.setTextColor(Color.RED);

if (TextUtils.equals(Turno,"F"))
      mHolder.txt_turno.setTextColor(Color.YELLOW);
}
return child;

}

hope that help you

OTHER TIPS

Try adding the text in HTML format. Im pretty sure this will change the color. Your code should look like:

public View getView(int pos, View child, ViewGroup parent) {
  Holder mHolder;
  LayoutInflater layoutInflater;
  if (child == null) {
     layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     child = layoutInflater.inflate(R.layout.row, null);
     mHolder = new Holder();
     mHolder.txt_turno = (TextView) child.findViewById(R.id.txt_turno);
     mHolder.txt_ore = (TextView) child.findViewById(R.id.txt_ore);
     mHolder.txt_id = (TextView) child.findViewById(R.id.txt_id);
     child.setTag(mHolder);
  } else {
     mHolder = (Holder) child.getTag();
  }

  if (turnoName.get(pos).toString().equalsIgnoreCase("M")){
     mHolder.txt_turno.setText(Html.fromHtml("<font color='#FF0000'>"+turnoName.get(pos)+"</font>"));
  }else if(turnoName.get(pos).toString().equalsIgnoreCase("F")){
     mHolder.txt_turno.setText(Html.fromHtml("<font color='#FFFF00'>"+turnoName.get(pos)+"</font>"));
  }else{
      mHolder.txt_turno.setText(Html.fromHtml("<font color='#FFFFFF'>"+turnoName.get(pos)+"</font>"));
  }
  mHolder.txt_ore.setText(oreName.get(pos));

  return child;
}

Change your getView with the code posted above.

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top