package com.example.gradecal;
import 생략(자동 import사용)
public class ScdFrag extends Fragment {
DBHelper dbHelper;
SQLiteDatabase db;
MyAdapter adapter;
ListView list;
Cursor cursor;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootview = inflater.inflate(R.layout.sub_2, container, false);
dbHelper = new DBHelper(getActivity());
db = dbHelper.getWritableDatabase();
list = (ListView) rootview.findViewById(R.id.grade_lst);
cursor = db.rawQuery("SELECT * FROM grade", null);
if (cursor.getCount() > 0) {
getActivity().startManagingCursor(cursor);
adapter = new MyAdapter(getActivity(), cursor);
list.setAdapter(adapter);
}
// getActivity().startManagingCursor(cursor);
// adapter = new MyAdapter(getActivity(), cursor);
// String[] from = {"_id", "sco"};
// int[] to = {android.R.id.text1, android.R.id.text2};
// SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(),
// android.R.layout.simple_list_item_2, cursor, from, to);
// list.setAdapter(adapter);
return rootview;
}
class MyAdapter extends CursorAdapter {
@SuppressWarnings("deprecation")
public MyAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
TextView txt1 = (TextView) view.findViewById(R.id.no);
TextView txt2 = (TextView) view.findViewById(R.id.tot);
TextView txt3 = (TextView) view.findViewById(R.id.sco);
TextView txt4 = (TextView) view.findViewById(R.id.gra);
// String no = cursor.getString(cursor.getColumnIndex("_id"));
// String tot = cursor.getString(cursor.getColumnIndex("tot"));
// String sco = cursor.getString(cursor.getColumnIndex("sco"));
// String gra = cursor.getString(cursor.getColumnIndex("gra"));
txt1.setText("번호 : " + context.getString(0));
txt2.setText("학점 : " + context.getString(1));
txt3.setText("점수 : " + context.getString(2));
txt4.setText("등급 : " + context.getString(3));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = LayoutInflater.from(context);
// LayoutInflater inflater = (LayoutInflater) mContext
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.id.grade_lst, parent, false);
return v;
}
}
}
프레그먼트에 커서어댑터 만들어서 커스텀 리스트뷰에 뿌리려는데 잘 안되네요 ㅠㅠ
왜 그런 걸까요;