SimpleCursorAdapterのデータの変更
-
23-10-2019 - |
質問
私はを使用するテレビガイドアプリに取り組んでいます ListActivity
1つのチャンネル / 1日ずつテレビ番組を表示します。私はaを使用しています RelativeLayout
のために ListView
アイテムと私は欲しいです ListView
このようなものを見るには:
07:00 The Breakfast Show
Latest news and topical reports
08:00 Tom and Jerry
More cat and mouse capers
のデータを取得します ListView
次のコードを使用したアイテム:
Cursor cursor = db.rawQuery(SELECT blah,blah,blah);
String[] columnNames = new String[]{"start_time","title", "subtitle"};
int[] resIds = new int[]{R.id.start_time_short, R.id.title, R.id.subtitle};
adapter = new SimpleCursorAdapter(this, R.layout.guide_list_item, cursor, columnNames, resIds);
私の問題はそれです start_time
フィールドはaです datetime
次の形式で:
2011-01-23 07:00:00
だから私が得るのはこれです:
2011-01-23 07:00:00 The Breakfast Show
Latest news and topical reports
2011-01-23 08:00:00 Tom and Jerry
More cat and mouse capers
私がやりたいことは、上記を使用してフォーマットすることです SimpleDateFormat
("HH:mm"
)だから、私はしか得られない hour:minute
の一部 start_time
分野。
私はそれを見つけました SimpleCursor.ViewBinder
インターフェイスは、それが私が望むものかもしれないことを示唆していますが、それを使用する方法を理解できません。私が正しいなら ViewBinder
, 、それを使用する方法についてコードをサンプリングするためのいくつかのポインターに感謝します。それ以外の場合は、他にどのように変更を達成できますか start_time
単に表示するフィールド HH:mm
フォーマット?
解決
あなたはこのようなことをすることができます:
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int column) {
if( column == 0 ){ // let's suppose that the column 0 is the date
TextView tv = (TextView) view;
String dateStr = cursor.getString(cursor.getColumnIndex("name_of_the_date_column"));
// here you use SimpleDateFormat to bla blah blah
tv.setText(theFormatedDate);
return true;
}
return false;
}
});
所属していません StackOverflow