我试图在我的android项目中实现Cursor Loader和Custom Cursor Adapter数据库(Sqlite本地数据库).我实际上想借助Cursor Loader和Adapter`将我的listview与本地数据库中的数据异步提供.下面是我的类,子类和方法
// Home Activity class
public class HomeActivity extends FragmentActivity implements LoaderCallbacks<Cursor> {
DotCursorAdapter mAdapter;
private ListView lv;
private final int LOADER_ID = 1932;
DatabaseHandler dbHelper = new DatabaseHandler(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_activity);
lv = (ListView) findViewById(R.id.lists);
mAdapter = new DotCursorAdapter(this, null,0);
lv.setAdapter(mAdapter);
getSupportLoaderManager().initLoader(LOADER_ID, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new DumbLoader(this);
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
mAdapter.swapCursor(cursor); …Run Code Online (Sandbox Code Playgroud) 我正在从这个站点http://www.ocpsoft.org/prettytime/实现漂亮的时间库, 以在我的 android 应用程序中获取带有文本的格式化日期字符串。
我将我的日期作为本地 sqlite 数据库中的字符串输入,
String dateString="2015-09-25 15:00:47";
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");
Date convertedDate = new Date();
try {
convertedDate = dateFormat.parse(dateString);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PrettyTime p = new PrettyTime();
String datetime= p.format(convertedDate);
textview.setText(datetime);
Run Code Online (Sandbox Code Playgroud)
我希望能够让我的日期格式parsetext类似
2 minutes ago
1 day ago
...
Run Code Online (Sandbox Code Playgroud)
然而,上面的代码片段只给了我文本并避免了时间。这就是它给出的
minutes ago
...
Run Code Online (Sandbox Code Playgroud)
请问有什么需要我做的吗,如果有人能提供帮助,我将不胜感激。谢谢