Это мой dbmanager
класс:
public class dbmanager extends SQLiteOpenHelper {
String sgpa_table="create table Sgpa (sname text, semester text, sgpa int,percent int, schemes int, primary key(sname,semester,schemes))";
public dbmanager(@Nullable Context context) {
super(context, "Student", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(sgpa_table);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public Cursor fetch_data1() {
SQLiteDatabase db = this.getWritableDatabase();
String query = "Select*FROM Sgpa" ;
Cursor cursor = db.rawQuery(query,null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
}
Это мой Adapter
класс:
public class adapter_sgpa extends RecyclerView.Adapter<adapter_sgpa.Viewholder> {
ArrayList<POJO> sgpaArrayList;
public adapter_sgpa(ArrayList<POJO> sgpaArrayList) {
this.sgpaArrayList = sgpaArrayList;
}
@NonNull
@Override
public adapter_sgpa.Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View listitem = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_sgpa, parent, false);
return new Viewholder(listitem);
}
@Override
public void onBindViewHolder(@NonNull adapter_sgpa.Viewholder holder, int position) {
POJO sgpa= sgpaArrayList.get(position);
holder.sname.setText(sgpa.getSname());
holder.semester.setText(sgpa.getSemester());
holder.sgpa.setText(Integer.toString(sgpa.getSgpa()));
holder.percent.setText(Integer.toString(sgpa.getPercent()));
holder.schemes.setText(Integer.toString(sgpa.getSchemes()));
}
@Override
public int getItemCount() {
return sgpaArrayList.size();
}
public class Viewholder extends RecyclerView.ViewHolder {
TextView sname, semester, sgpa, percent, schemes;
//ImageButton btndelete1;
public Viewholder(@NonNull View itemView) {
super(itemView);
sname = (TextView) itemView.findViewById(R.id.textView2);
semester = (TextView) itemView.findViewById(R.id.semester);
sgpa = (TextView) itemView.findViewById(R.id.textV);
percent = (TextView) itemView.findViewById(R.id.textVw);
schemes = (TextView) itemView.findViewById(R.id.scheme1);
// btndelete1 = (ImageButton) itemView.findViewById(R.id.btndelete1);
}
}
}
Это sgpa_frag, который похож на мой основной класс:
public class sgpa_frag extends Fragment {
//View view;
RecyclerView recyclerview;
adapter_sgpa ac;
TextView else2;
ArrayList<POJO> sgpaArrayList;
public sgpa_frag() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sgpa_frag, container, false);
recyclerview= (RecyclerView) view.findViewById(R.id.rc1);
else2=(TextView)view.findViewById(R.id.else2);
sgpaArrayList= new ArrayList<>();
ac= new adapter_sgpa(sgpaArrayList);
recyclerview.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,true));
recyclerview.setAdapter(ac);
Fetchdata1();
return view;
}
private void Fetchdata1()
{
dbmanager db= new dbmanager(getContext());
Cursor cursor= db.fetch_data1();
if (cursor!= null){
cursor.moveToFirst();
while (cursor.moveToNext()){
//ModelDetail cd= new ModelDetail(cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4));
POJO pj= new POJO();
pj.setSname(cursor.getString(0));
pj.setSemester(cursor.getString(1));
pj.setSgpa(cursor.getInt(2));
pj.setPercent(cursor.getInt(3));
pj.setSchemes(cursor.getInt(4));
sgpaArrayList.add(pj);
}
ac= new adapter_sgpa(sgpaArrayList);
recyclerview.setAdapter(ac);
}
else{
else2.setVisibility(View.VISIBLE);
}
}
}
Первая строка моей базы данных SQLite не извлекается и не отображается в моем RecyclerView
. Другие строки отображаются, но только первая строка 1016 * не отображается. Может кто-нибудь указать мне, где я иду не так?