안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요 질문 좀 드릴게요..제가 그리드뷰를 이용해서 버튼을 여러개 구현했는데요
각 버튼마다 색깔을 지정해주고 싶은데
모든 버튼이 같은색이 되어버리네요..
빨간색으로 칠한것에 문제가 있는것 같은데.. 어떻게 해야할까요??
class GridSetAdapter extends BaseAdapter{
private ArrayList<GridSet> object;
public GridSetAdapter(ArrayList<GridSet> object){
super();
this.object=object;
}
public int getCount() {
return object.size();
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null){
LayoutInflater inflater=LayoutInflater.from(Testp2Activity.this);
convertView=inflater.inflate(R.layout.sub,parent,false);
holder=new ViewHolder();
holder.btnname=(Button)convertView.findViewById(R.id.btn);
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
private ArrayList<GridSet> object;
public GridSetAdapter(ArrayList<GridSet> object){
super();
this.object=object;
}
public int getCount() {
return object.size();
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null){
LayoutInflater inflater=LayoutInflater.from(Testp2Activity.this);
convertView=inflater.inflate(R.layout.sub,parent,false);
holder=new ViewHolder();
holder.btnname=(Button)convertView.findViewById(R.id.btn);
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
holder.btnname.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Log.d("", "온클릭 리스너 실행");
i=position;
showAlertDialog(v);
}
});
String name=object.get(position).getName();
strByte3=name.getBytes();
if(name.equals("")){
holder.btnname.setBackgroundColor(00000000);
}
else{
holder.btnname.setBackgroundColor(col2[i]); //여기 col2[i]에 해당되는 색으로만 모든 버튼이 바뀌네요ㅠㅜ
}
public void onClick(View v){
Log.d("", "온클릭 리스너 실행");
i=position;
showAlertDialog(v);
}
});
String name=object.get(position).getName();
strByte3=name.getBytes();
if(name.equals("")){
holder.btnname.setBackgroundColor(00000000);
}
else{
holder.btnname.setBackgroundColor(col2[i]); //여기 col2[i]에 해당되는 색으로만 모든 버튼이 바뀌네요ㅠㅜ
}
holder.btnname.setText(name);
return convertView;
}
}
return convertView;
}
}
궁금한게 holder.btnname.setText(name); 에서는 한개 버튼만 텍스트가 바뀌는데
빨간색 셋백그라운드컬러에서는 모든버튼의 색이 바뀌네요..
왜 이러는거죠?ㅠㅠ;
holder.btnname.setText(name);
이게 if문 밖에있어서 그런거 아닌가요?..................아닌가;
질문 내용 이해가 잘...