jusarow 레이아웃에 체크박스와 텍스트뷰1,2 를 주고 jusa 레이아웃에 리스트뷰에서 출력하는 방법입니다.
onCheckedChanged매소드 부분에서 값이 안받아져와서요 오류는 안나는데 어디서 틀렸는지 체크박스 값이 출력이 안되요
설명좀 바랍니다...
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
public class Jusa extends ListActivity {
TextView text, text2;
String [] vaccin = {"복숭아","딸기","바나나","자두","포도","살구","토마토"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jusa);
//Adapter생성
RowAdapter1 adapter = new RowAdapter1(this, R.layout.jusarow,vaccin);
//Listview에 어뎁터 적용
setListAdapter(adapter);
}
}
//Adapter Class
class RowAdapter1 extends ArrayAdapter<String> implements OnCheckedChangeListener{
//작업에 필요한 Context객체
Context context;
String [] data;
int resID;
CheckBox check;
TextView text2,text1 ;
//생성자
public RowAdapter1 (Context c, int resID,String [] data){
super(c, resID,data);
this.data = data;
this.context = c;
this.resID = resID;
}
//실제 ListView의 항목을 만드는 메소드
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row==null){
Activity activity = (Activity)context;
LayoutInflater inflater = activity.getLayoutInflater();
//LayoutInflater를 이요하여 View객체 생성.
row = inflater.inflate(R.layout.jusarow,null);
}
//위젯추출
text1 = (TextView)row.findViewById(R.id.TextView01);
text2 = (TextView)row.findViewById(R.id.TextView02);
check = (CheckBox) row.findViewById(R.id.CheckBox01);
//값 셋팅
text1.setText(data[position]);
check.setOnCheckedChangeListener(this);
//View리턴
return row;
}
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
arg1 = true;
// 체크박스의 값을 가져온다.
if(arg0 == check){
if(arg1 == true){
text2.setText("체크되었습니다");
}else{
text2.setText("체크되지 않았습니다.");
}
}
}
}