我遇到的问题是我想将数据库转储到列表视图中,但出现错误,我不知道是否是因为我做错了事。
public class MisEntradasLocal extends ListFragment{
private ListView list;
private SQLiteDatabase db;
ArrayList <String> entradas;
private DbHelper dbHelper;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_mis_entradas_local,container,false);
list = (ListView) view.findViewById(R.id.lista);
dbHelper = new DbHelper(getContext());
entradas = new ArrayList<>();
ArrayList <String> items = new ArrayList<>();
SQLiteDatabase db=dbHelper.getReadableDatabase();
Cursor fila= db.rawQuery("select * from entradas",null);
if(fila.moveToFirst()){
do{
items.add("Entrada: "+fila.getString(1));
}while (fila.moveToNext());
}
ArrayAdapter<String > listadapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,items);
list.setAdapter(listadapter);
return view;
}
}
Databse包含一个String字段,其idEntrada和其他字符串nombreEvento。
答案 0 :(得分:0)
我发现了问题。那是我从ListFragment扩展而来,然后将其更改为普通片段。