2
SQLite 데이터베이스를 사용하여 ListFragment를 구현하는 가장 좋은 방법은 무엇입니까? 현재 DBAdapter를 작성하여 SimpleCursorAdapter에 레코드를 열고 닫고 쉽게 가져올 수 있습니다. 나는 각 탭마다 다른 ListView를 표시하고자하는 탐색 탭이있는 ActionBar를 구현하는 MainActivity를 가지고 있습니다. 여기 SQLite 데이터베이스로 ListFragment를 사용하는 Android 디자인
내 ListFragment입니다 : 여기public class MaterialsListFragment extends ListFragment {
public DBAdapter db;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.portrait_material_view, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// create new DBAdapter
db = new DBAdapter(getActivity());
db.open();
Cursor c = db.getAllRecords();
String[] from = new String[] { DBAdapter.KEY_IDNO, DBAdapter.KEY_MATERIAL };
int[] to = new int[] { R.id.idno, R.id.materials };
// Now create an array adapter and set it to display using our row
MyListAdapter materials = new MyListAdapter(this, R.layout.list_cell, c, from, to);
setListAdapter(materials);
}
지금은 그것의 자신의 클래스 파일에 MyListAdapter 코드 :
public class MyListAdapter extends SimpleCursorAdapter {
public MyListAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to) {
super(context, layout , cursor, from, to);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Create the idno textview with background image
TextView idno = (TextView) view.findViewById(R.id.idno);
idno.setText(cursor.getSring(3));
// create the material textview
TextView materials = (TextView) view.findViewById(R.id.materials);
materials.setText(cursor.getString(1));
}
}
이 이것에 대해 갈 수있는 방법이 있나요이? 나는 당신이 가지고 있거나 좋은 예를 알고 있다면 어떤 제안이라도 고맙게 생각합니다.