제가 전화번호부를 가져와서 click한 주소록에 관하여 DB에 insert하고 text color를 DB가 insert,delete되는 조건에 따라서 변경 하려고 하는데 이상하게도 화면에 비춰지는 list중 가장 상단에 있는 것에 색이 변합니다. position문제 같은데 제가 이번에 처음 하는거라 감이 안오네요 질문도 하다보니 횡설수설하고.... 죄송합니다 ㅜ
//==============================
//===============================
안의 부분이 색깔을 변경하는건데 따로 position을 다시 지정해줘야되는건지 어떻게 해야될지 조언 부탁드립니다.
질문에 부족한점이 있음 얘기해주시면 바로바로 추가하겠습니다.
@Override
protected void onResume() {
super.onResume();
adapter = new ContactsAdapter(ContactListActivity.this,
R.layout.layout_phonelist, getContactList());
lv_contactlist.setAdapter(adapter);
lv_contactlist
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> contactlist, View v,
int position, long resid) {
Contact phonenumber = (Contact) contactlist
.getItemAtPosition(position);
if (phonenumber == null) {
return;
}
if (phonenumber.getCheck()==true){
//====================================================================
TextView tvTest = (TextView)findViewById(R.id.tv_name);
TextView tvTest1 = (TextView)findViewById(R.id.tv_phonenumber);
String strColor = "#4646CD";
String strColor1 = "#5F87E1";
tvTest.setTextColor(Color.parseColor(strColor));
tvTest1.setTextColor(Color.parseColor(strColor1));
//====================================================================
phonenumber.setCheck(false);
manager.deletePhone(phonenumber.getPhonenum());
}else if(phonenumber.getCheck() == false){
//====================================================================
TextView tvTest = (TextView)findViewById(R.id.tv_name);
TextView tvTest1 = (TextView)findViewById(R.id.tv_phonenumber);
String strColor = "#FF0000";
tvTest.setTextColor(Color.parseColor(strColor));
tvTest1.setTextColor(Color.parseColor(strColor));
//====================================================================
phonenumber.setCheck(true);
DBInsert(phonenumber.getName(),phonenumber.getPhonenum());
}
}
});
}
밑에 분이 얘기하신거 보고 제가 이해한대로 해봤는데
if (.getCheck()==true)
조건에서 .getCheck() 부분에서 조건이 자꾸 에러가나는데 혹시 알 수 있나요????
private class ContactsAdapter extends ArrayAdapter<Contact> {
private int resId;
private ArrayList<Contact> contactlist;
private LayoutInflater Inflater;
private Context context;
public ContactsAdapter(Context context, int textViewResourceId,
List<Contact> objects) {
super(context, textViewResourceId, objects);
this.context = context;
resId = textViewResourceId;
contactlist = (ArrayList<Contact>) objects;
}
@Override
public View getView(int position, View v, ViewGroup parent) {
final ViewHolder holder;
final int checkboxposition = position;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(resId, null);
holder = new ViewHolder();
holder.tv_name = (TextView) v.findViewById(R.id.tv_name);
holder.tv_phonenumber = (TextView) v.findViewById(R.id.tv_phonenumber);
holder.iv_photoid = (ImageView) v.findViewById(R.id.iv_photo);
//holder.iv_checkbox = (CheckBox) v.findViewById(R.id.iv_checkbox);
v.setTag(holder);
//======================================================================
holder.tv_name.setBackgroundResource(R.drawable.list_item_0);
holder.tv_phonenumber.setBackgroundResource(R.drawable.list_item_0);
holder.iv_photoid.setBackgroundResource(R.drawable.list_item_0);
//holder.iv_checkbox.setBackgroundResource(R.drawable.list_item_0);
//======================================================================
//====================================================================
if (.getCheck()==true){
TextView tvTest = (TextView)findViewById(R.id.tv_name);
TextView tvTest1 = (TextView)findViewById(R.id.tv_phonenumber);
String strColor = "#FF0000";
tvTest.setTextColor(Color.parseColor(strColor));
tvTest1.setTextColor(Color.parseColor(strColor));
}else if(.getCheck() == false){
TextView tvTest = (TextView)findViewById(R.id.tv_name);
TextView tvTest1 = (TextView)findViewById(R.id.tv_phonenumber);
String strColor = "#4646CD";
String strColor1 = "#5F87E1";
tvTest.setTextColor(Color.parseColor(strColor));
tvTest1.setTextColor(Color.parseColor(strColor1));
}
//====================================================================
Contact acontact = contactlist.get(checkboxposition);
} else {
holder = (ViewHolder) v.getTag();
}
acontact = contactlist.get(position);
if (acontact != null) {
holder.tv_name.setText(acontact.getName());
holder.tv_phonenumber.setText(acontact.getPhonenum());
//holder.iv_checkbox.setSelected(((ListView)parent).isItemChecked(position));
Bitmap bm = openPhoto(acontact.getPhotoid());
// 사진없으면 기본 사진 보여주기
if (bm != null) {
holder.iv_photoid.setImageBitmap(bm);
} else {
holder.iv_photoid.setImageDrawable(getResources()
.getDrawable(R.drawable.default1));
}
}
return v;
}