我将使用 RecyclerView 作为节标题
我想在 SQLite 数据库中插入每个日期和时间数据时创建节标题
我按照以下链接获取了此解决方案,但没有成功
请参考下图
对于上面的图像数据,使用以下代码或部分是静态的:
List<Company> childList = new ArrayList<>();
List<CompanySectionHeader> sectionHeaders = new ArrayList<>();
childList = myDb.getAllCompany();
sectionHeaders.add(new CompanySectionHeader(childList, "WEDNESDAY 4 APRIL", 1));
现在,如果假设我输入今天的数据,那么我将创建 1 个采用今天日期的节标题
下面的图像数据部分标题也是静态或数据:
上面的图像数据正在使用下面的代码获取:
childList.add(new Company("Ketul Inc.", "11/11/2017 3:46 PM"));
childList.add(new Company("Atmel Corporation", "09/19/2017 8:46 PM"));
childList.add(new Company("ABC Technologies", "09/12/2017 7:41 PM"));
childList.add(new Company("Huron Capital Partners LLC", "09/12/2017 7:25 PM"));
sectionHeaders = new ArrayList<>();
//Create a List of SectionHeader DataModel implements SectionHeader
sectionHeaders.add(new CompanySectionHeader(childList, "SATURDAY 7 APRIL", 2));
下面的代码是我的SectionHeader.Java
:
public class CompanySectionHeader implements Section<Company>, Comparable<CompanySectionHeader> {
List<Company> childList;
String sectionText;
int index;
public CompanySectionHeader(List<Company> childList, String sectionText, int index) {
this.childList = childList;
this.sectionText = sectionText;
this.index = index;
}
@Override
public List<Company> getChildItems() {
return childList;
}
public String getSectionText() {
return sectionText;
}
@Override
public int compareTo(CompanySectionHeader another) {
if (this.index > another.index) {
return -1;
} else {
return 1;
}
}
}
下面是我的 SQLite 数据库结构:
public String getFromatDate(long dateTime) {
String formatedDate;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(dateTime);
Date mDate = calendar.getTime();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm a", new Locale("en"));
formatedDate = sdf.format(mDate);
return formatedDate;
}
public long insertCompany(Company company){
//String sql = null;
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DatabaseHelper.KEY_COMPANY_NAME, company.getName());
values.put(DatabaseHelper.KEY_CREATED_AT, System.currentTimeMillis());
values.put(DatabaseHelper.KEY_UPDATED_AT, System.currentTimeMillis());
values.put(DatabaseHelper.KEY_COMPANY_WEBSITE,company.getWebsite());
values.put(DatabaseHelper.KEY_COMPANY_EMAIL,company.getEmail());
values.put(DatabaseHelper.KEY_COMPANY_PHONE_HOME,company.getPhoneHome());
long company_id = db.insert(COMPANY, null, values);
return company_id;
}
我的问题是如何动态创建节标题
如果您需要任何代码或信息,可以问我:)
提前致谢 :