구글링해서 하라는건 다 해본것 같은데 잘 안됩니다..
도대체 이유를 모르겠습니다.. 도와주세요 고수님들!
ProtectorAdapter.java
package com.example.customviewtest;
import java.util.ArrayList;
import java.util.Hashtable;
import android.R.integer;
import android.content.Context;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
public class ProtectorAdapter extends BaseAdapter {
Context context;
LayoutInflater Inflater;
View v;
ArrayList<ProtectorItem> arryList = new ArrayList<ProtectorItem>();
TextView tvProtector, tvContactNum;
CheckBox ckbox;
private int layout;
public ProtectorAdapter(Context context, int layout,
ArrayList<ProtectorItem> arrayList) {
this.context = context;
this.layout = layout;
this.arryList = arrayList;
// LayoutInflater 객체를 Inflater로 반환받는다.
Inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arryList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arryList.get(position).getProtector();
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final int finalPosition = position;
// 반환받은 LayoutInflater 객체로부터 레이아웃 객체를 반환받는다. 첫번째 인수는 inflate할 대상의 xml
// 리소스, 두 번째 인수는 생성된 뷰의 루트로 사용할 뷰 객체. 리소스 내에 루트가 따로 있다면 null.
if (convertView == null) {
convertView = Inflater.inflate(layout, parent, false);
} else {
tvProtector = (TextView) convertView.findViewById(R.id.protector);
tvContactNum = (TextView) convertView.findViewById(R.id.contactNum);
tvProtector.setText(arryList.get(finalPosition).getProtector());
tvContactNum.setText(arryList.get(finalPosition).getContactNum());
ckbox = (CheckBox) convertView.findViewById(R.id.check);
ckbox.setChecked(arryList.get(finalPosition).getAllow());
}
return convertView;
}
}
ProtectorItem.java//////////////////////////////////////////////////////////////////
package com.example.customviewtest;
public class ProtectorItem {
private int id;
private String protector;
private String contactNum;
private boolean allow;
public ProtectorItem(){
}
public ProtectorItem(int id, String protector, String contactNum, boolean allow){
this.id = id;
this.protector = protector;
this.contactNum = contactNum;
this.allow = allow;
}
public boolean getAllow(){
return allow;
}
public int getId(){
return id;
}
public String getProtector(){
return protector;
}
public String getContactNum(){
return contactNum;
}
}
protector_list.xml//////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:focusable="false" >
<TextView
android:id="@+id/protector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/check"
android:focusable="false" >
<TextView
android:id="@+id/contactNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@id/protector"
android:layout_toRightOf="@id/protector"
android:focusable="false"
android:text="" >
</TextView>
</TextView>
</CheckBox>
</RelativeLayout>
</LinearLayout>
activity_emergency_contact.xml////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="보호자 및 긴급 연락처 목록" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="mOnClick"
android:text="추가" />
<Button
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="mOnClick"
android:text="삭제" />
</LinearLayout>
<ListView
android:id="@+id/contactList"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
