저는 안드로이드와 새로운 소프트웨어를 개발했습니다. 체크 박스가있는 사용자 목록보기, 체크 박스 데이터를 데이터베이스에 삽입하는 방법 안 그래? 내 데이터베이스 클래스에서목록보기 및 체크 박스 (데이터베이스 (sqlite) 넣기 방법)
, 난 정말 답을 찾기 위해 노력
createntry(String number,String name) // in my database class
내 데이터베이스에 이름과 번호를 추가하는 데 사용하는 기능을 가지고 있고이 대한의 getView 기능을 사용한다 파악,하지만 여전히 솔루션을 찾을 수 없습니다.
내 CursorAdapterClass
public class ContactCursorAdapterCT extends CursorAdapter {
private ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
private Context context1;
DataBaseBON dd1= new DataBaseBON(context1);
public ContactCursorAdapterCT(Context context, Cursor c) {
super(context, c);
this.context1 = context;
for (int i = 0; i < this.getCount(); i++) {
itemChecked.add(i, false); // initializes all items value with false
}
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView name = (TextView)view.findViewById(R.id.contactlistTV1);
name.setText(cursor.getString
(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)));
TextView phone = (TextView)view.findViewById(R.id.contactlistTV2);
phone.setText(cursor.getString
(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.lvct, parent, false);
bindView(v, context, cursor);
return v;
}
public View getView(final int pos, View inView, ViewGroup parent) { //getView
if (inView == null) {
LayoutInflater inflater = (LayoutInflater) context1
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inView = inflater.inflate(R.layout.lvct, null);
}
final CheckBox cBox = (CheckBox)inView.findViewById(R.id.checkBox1); // my
// CheckBox
cBox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v.findViewById(R.id.checkBox1);
if (cb.isChecked()) {
itemChecked.set(pos, true);
//My problem should be here??
} else if (!cb.isChecked()) {
itemChecked.set(pos, false);
}
}
});
cBox.setChecked(itemChecked.get(pos)); // this will Check or Uncheck the
// CheckBox in ListView
// according to their original
// position and CheckBox never
// loss his State when you
// Scroll the List Items.
return inView;
내 활동 클래스
public class Contacts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts);
Cursor cursor = getContentResolver().query
(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
startManagingCursor(cursor);
ContactCursorAdapterCT adapter= new ContactCursorAdapterCT
(Contacts.this, cursor);
ListView contactLV = (ListView) findViewById(R.id.listviewblcontactsDB);
contactLV.setAdapter(adapter);
내 데이터베이스 클래스 다음
public long creatEntry(String inputnumber , String name) { // for add data
// TODO Auto-generated method stub
ContentValues cv= new ContentValues();
cv.put(KEY_NUMBER, inputnumber);
cv.put(N_NAME, name);
Log.v(inputnumber, "adding to Database");
return ourdatabase.insert(DATABASE_TABLE, null, cv);
}
어디에서 createntry 기능을 호출해야합니까? –