Grade1
部分Grade1A, Grade1B
,课程{ {1}}基于用户输入的章节Grade2
等。我在行Grade2A, Grade2B
中使用Sections content
来获取数据库的内容。但Log.i("Sections content", sb.toString());
显示空白/显示注释。贝娄是我的源代码。为什么LogCat
显示为空白?我没有做对的是什么。过去一周,我尝试通过许多来源解决这个问题,但没有解决方案。我非常感谢你们。
此代码添加一个新部分,并在logcat中显示类及其新添加的部分
Logcat
DBHelperClass private void intitializeListenersCSOS(){
addSectionBtnID.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String sectionNameValue = edittable_sectionName.getText().toString();
String sectionDescriptionValue = edittable_sectionDescription.getText().toString();
if( (sectionNameValue.length() > 0) && sectionDescriptionValue.length()>0){
sectionsBean.setSections_name(sectionNameValue);
sectionsBean.setSections_description(sectionDescriptionValue);
demeaSQL.addSections(sectionsBean,selectClassSpinner.getSelectedItemId());
if (demeaSQL != null) {
edittable_sectionName.setText("");
edittable_sectionDescription.setText("");
displayClassAndSectionsList();
Toast.makeText(ClassSectionOnSetup.this, "Section Added!! Add more section", Toast.LENGTH_LONG).show();
StringBuilder sb = new StringBuilder();
for (SectionsBean s : demeaSQL.getAllSectionsByClassesID()) {//getAllSections()
sb.append(" SectionName= " + s.getSections_name() + " SectionID= " + s.getSectionsID());
sb.append("\n");
}
Log.i("Sections content", sb.toString());
Toast.makeText(getApplicationContext(), "Added Successfully", Toast.LENGTH_SHORT).show();
} else {
Log.i("Sections Err", "Database Error");
}
}
}
});
}
向数据库添加部分
addSections()
DBHelperClass public long addSections(SectionsBean sectionsBean, long selectClassID){
long sectionid = -1;
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_CLASSES_SECTIONS_NAME, sectionsBean.getSections_name());
values.put(COLUMN_CLASSES_SECTIONS_DESCRIPTION,sectionsBean.getSections_description());
long sectionsID = db.insert(TABLE_CLASSES_SECTIONS, null, values);
if (sectionid > 0 && selectClassID > 0) {
values.clear();
values.put(COLUMN_CLASSLINK, selectClassID);
values.put(COLUMN_SECTIONLINK, sectionsID);
db.insert(TABLE_CLASSES_SECTIONS_LINK, null, values);
//db.close();
}
return sectionid;
}
根据班级获取部分。
getAllSectionsByClassesID()