ListFragment にアイテムをリストするアプリケーションがあります。各アイテムの背景色は、アイテムのステータスに基づいて異なります。アイテムは SQL に格納されるため、アダプターは SimpleCursorAdapter からサブクラス化されます。これらのアイテムの編集は、別のフラグメントで行われます。ステータスが変更されたら、AsyncTask を使用して GUI スレッドの Adapter で notifyDataSetChanged() をトリガーします。しかし、私のリストは更新されていません。
確認するために notifyDataSetChanged クラスをオーバーライドしたため、GUI スレッドにいることはわかっています。同じトレースは、ルーチンに到達していることも示しています。
@Override
public void notifyDataSetChanged() {
String tag = TAG + ".notifyDataSetChanged()";
Log.d(tag,"DATA SET CHANGE NOTIFICATION!");
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
Log.d(tag,"On GUI thread!");
} else {
Log.d(tag,"NOT on GUI thread!");
}
super.notifyDataSetChanged();
}
提案をいただければ幸いです。お時間と関心をお寄せいただきありがとうございます。
アダプタ全体は次のとおりです。
public class OrderListAdapter extends SimpleCursorAdapter {
private static final String TAG = "OrderListAdapter";
Context _context = null;
int layoutResourceId = 0;
/**
* Constructor
* @param context - Context
* @param layout - Layout
* @param c - Cursor
* @param from - String array with column names
* @param to - Int array with destination field ids
* @param flags - Integer with flags
*/
public OrderListAdapter(Context context, int layout, Cursor c,
String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
_context = context;
}
/**
* This override version changes the color of the background of the
* row based on the order status.
*/
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (view == null) {
LayoutInflater inflater = ((Activity)_context).getLayoutInflater();
view = inflater.inflate(R.layout.fragment_order_list_row, null);
}
setRowColor(view);
return view;
}
private void setRowColor(View view) {
Cursor cursor = getCursor();
int col = cursor
.getColumnIndex(DBContract.DeliveryOrderTable.ENROUTE_FLAG);
String enroute_flag = cursor.getString(col);
col = cursor
.getColumnIndex(DBContract.DeliveryOrderTable.DELIVERED_DATETIME);
String deliveredDateStr = cursor.getString(col);
int bgColorId = 0;
if (!deliveredDateStr.equals("")) {
bgColorId = R.color.bg_status_delivered_color;
} else if (enroute_flag.startsWith("t") || enroute_flag.startsWith("y")) {
bgColorId = R.color.bg_status_enroute_color;
} else {
bgColorId = R.color.bg_status_assigned_color;
}
view.setBackgroundColor(_context.getResources().getColor(bgColorId));
} // setRowColor()
///// DEBUG
@Override
public void notifyDataSetChanged() {
String tag = TAG + ".notifyDataSetChanged()";
Log.d(tag,"DATA SET CHANGE NOTIFICATION!");
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
Log.d(tag,"On GUI thread!");
} else {
Log.d(tag,"NOT on GUI thread!");
}
super.notifyDataSetChanged();
}
} // class