2014-04-16 3 views
0

내 디스플레이 어댑터에서 필자는 데이터베이스의 데이터를 시각화합니다. TextView 턴과 관련된 열의 M 값이 빨간색으로 표시되기를 바랍니다. 어떻게해야합니까?문자열 값을 기반으로 색상을 지정하는 방법

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; 
    } 
} 
+2

당신의 질문이 확실하지 않습니다 –

+0

난 열의 M 값이 바뀌기를 바란다. – user3461181

+0

'나는 TextView 차례에 비례하여 칼럼의 M 값을 원한다. 평균? –

답변

0

이상한 ... 나를 위해 작동한다 : 이 시도 : 당신에게 HTML 형식의 텍스트를 추가

+0

컬럼 이동에는 다른 값이 있으므로 M과 M의 값이 빨간색으로 염소화되어야한다면 다른 값이 흰색 인 채로 남아 있어야합니다 – user3461181

+0

제안을 시도했지만 작동하지 않으면 다음을 시도했습니다. – user3461181

+0

고마워 이제 작동합니다. – user3461181

0

시도 도움

 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; 

}

희망. 임 꽤 확신이 색상을 바꿀 것입니다. 귀하의 코드는 다음과 같아야합니다 :

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; 
} 

위에 게시 된 코드로 getView를 변경하십시오.

희망이 있습니다.

관련 문제