안드로이드 개발 질문/답변
(글 수 45,052)
//ListView선언! ListView lv = (ListView)findViewById(R.id.phonebook_listview); //ListView에 적용될 어댑터 선언부분 private class PhoneListAdapter extends ArrayAdapter<SurePhonebook> { //private int m_ClickPosition = -1; public PhoneListAdapter( Context context, int textViewResourceId, ArrayList<SurePhonebook> _items ) { super( context, textViewResourceId, _items ); Log.i(PHONEBOOKTAG, " =========== SurePhoneListAdapter Start =========== "); } @Override public View getView( int position, View convertView, ViewGroup parent ) // 한줄을 표시하는 함수 { //m_ClickPosition = position ; int bgColor = SureMiniCommon.bgColorDeSelected; // bgColor - 지금은 안쓴다. View v = convertView; if ( v == null ) { // 이미 화면에 구성되어 있지 않다면 LayoutInflater vi = // Layout Inflater 를 이용해서 Layout을 만들어 메모리에 구성한다. ( LayoutInflater ) getSystemService( Context.LAYOUT_INFLATER_SERVICE ); v = vi.inflate( R.layout.phonebook_list, null ); // 만든 layout을 화면에 구성. }//phonebook_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="center" android:layout_height="wrap_content" android:id="@+id/LinearLayout01">
<LinearLayout android:layout_height="wrap_content"
android:background="@drawable/phonebook_listbackground"
android:layout_width="fill_parent"
android:gravity="center"
android:id="@+id/phonebookListLayout">
<TextView android:id="@+id/phonebook_name"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_width="120px"
android:layout_marginLeft="30px"
android:text="phonebookName" >
</TextView>
<TextView android:layout_height="wrap_content"
android:text="phonebookCallPhone"
android:id="@+id/phonebook_callphone"
android:textColor="#000000"
android:layout_width="140px"
android:layout_marginLeft="10px" >
</TextView>
<TextView android:layout_height="wrap_content"
android:id="@+id/phonebook_group"
android:text="phonebookGroup"
android:gravity="center"
android:textColor="#000000"
android:layout_width="150px" >
</TextView>
</LinearLayout>
</LinearLayout>
고수님들 꼭좀 도와주시길 바랍니다!!
간단하게 ListView에 phonebook_list.xml을 인플레이트 시켜서 나타내는 소스코드입니다.
여기서 문제는 아이템 클릭시 해당 뷰(리니어레이아웃)의 백그라운드를 변경하고 싶은데(현재는 R.drawable.phonebook_listBackground)
listView에서 onItemClickListener를 선언해서
lv.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
}
});
view.setBackgroundResources(R.drawable.phonebook_checkBackground)로 했더니 먹지도 않고,
억지로 적용시켜봤더니
1번째 부분의 background가 바뀌면 11번째 부분의 background도 동시에 바뀌는 문제가 발생합니다.
어떻게 해결해야 할까요? ㅜㅜ
좀 해석하는데 오래걸리겟지만 정말 고수님들 부탁드립니다