2012-01-13 2 views
0

Ok 지금까지 이것을 작성했고 항목이 표시되고 있습니다. 행과 같은 수의 요소가있는 배열에 키 값을 가지고 있다고 가정 해 보겠습니다. 16 행이 있으면 배열에 16 개의 요소가 있습니다. 배열 [0]을 확인하고 setColor 값에 따라 첫 번째 행을 확인한 다음 배열 [1]과 setColor를 다음 행으로 확인합니다. 누군가가 나를 도울 수의 getView에서customadapter에서 행 색칠하기 android

public class SimpleAdapter extends ArrayAdapter<String>{ 

private final Context context; 



private String data[] = null; 

    public SimpleAdapter(Context context, String[] data) { 
     super(context, R.layout.row, data); 
     this.context = context; 
     this.data = data; 
    } 



    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View rowView = inflater.inflate(R.layout.row, parent, false); 
     TextView textView = (TextView) rowView.findViewById(R.id.text1); 
     textView.setText(data[position]); 
     return rowView; 
    } 
} 
+0

를 사용하면 목록보기에서 항목의 배경색을 변경하려면 또는 거기에 텍스트 뷰에 대한 setTextColor을 변경 하시겠습니까? –

+0

중복 가능성이 있습니까? http://stackoverflow.com/questions/2217753/changing-background-color-of-listview-items-on-android –

+0

setText 색상. 그것은 정확한 복제가 아니야, 나는 그것을 읽었지만 문제는 내가 원하는 매개 변수를 전달하는 방법을 모르겠다 (배열 의미) – ghostrider

답변

0

를()는 같은 것을 가질 수있는 것은 :

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View rowView = inflater.inflate(R.layout.row, parent, false); 
TextView textView = (TextView) rowView.findViewById(R.id.text1); 
textView.setText(data[position]); 

switch(position) { 
    case 0: 
    rowView.setBackgroundColor(color0) 
    break; 
    case 1: 
    rowView.setBackgroundColor(color1) 
    break; 
... 
} 

return rowView; 
+0

그것이 내가 의미했던 것이었다. 감사!! – ghostrider

0

이 배열에 color/(background drawable)을 정의 간단하다. 같은

int[] color = {your colors }; 

다음 바로 아래 라인

int mycolor = position % color.length; 
rowView.setBackground/color = color[mycolor]; 
TextView textView = (TextView) rowView.findViewById(R.id.text1); 
textView.setText(data[position]); 
return rowView; 
관련 문제