DataListFragment (ListFragment を拡張) 内に新しいデータを表示しようとしています。MainActivity 内で行う方法は次のとおりです。
CustomArrayAdapter adapter = new CustomArrayAdapter(this);
adapter.setData1(newContent);
adapter.notifyDataSetChanged();
ToFragment.changeAdapter(adapter);
CustomArrayAdapter は次のようになります。
public class CustomArrayAdapter extends ArrayAdapter<FinalData> {
private final LayoutInflater mInflater;
public CustomArrayAdapter(Context context) {
super(context, android.R.layout.simple_list_item_2);
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setData1(ArrayList<FinalData> data) {
System.out.println("chch");
clear();
System.out.println("chch");
if (data != null) {
for (FinalData appEntry : data) {
add(appEntry);
System.out.println("chch");
}
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
view = mInflater.inflate(R.layout.single_item, parent, false);
} else {
view = convertView;
}
FinalData item = getItem(position);
if (position % 2 == 0) {
((TextView)view.findViewById(R.id.train_info)).setEllipsize(TruncateAt.MARQUEE);
((TextView)view.findViewById(R.id.train_info)).setSelected(true);
((TextView)view.findViewById(R.id.stations_info)).setEllipsize(TruncateAt.MARQUEE);
((TextView)view.findViewById(R.id.stations_info)).setSelected(true);
((TextView)view.findViewById(R.id.stations_info)).setText(item.getFullData());
((AutoResizeTextView)view.findViewById(R.id.time_info)).setText(item.getShortData());
((TextView)view.findViewById(R.id.train_info)).setText(item.getTimeData());
((TextView)view.findViewById(R.id.train_info)).setBackgroundColor(Color.parseColor("#6dcaec"));
((TextView)view.findViewById(R.id.stations_info)).setBackgroundColor(Color.parseColor("#a8dff4"));
((AutoResizeTextView)view.findViewById(R.id.time_info)).setBackgroundColor(Color.parseColor("#6dcaec"));
} else {
((TextView)view.findViewById(R.id.train_info)).setEllipsize(TruncateAt.MARQUEE);
((TextView)view.findViewById(R.id.train_info)).setSelected(true);
((TextView)view.findViewById(R.id.stations_info)).setEllipsize(TruncateAt.MARQUEE);
((TextView)view.findViewById(R.id.stations_info)).setSelected(true);
((TextView)view.findViewById(R.id.stations_info)).setText(item.getFullData());
((AutoResizeTextView)view.findViewById(R.id.time_info)).setText(item.getShortData());
((TextView)view.findViewById(R.id.train_info)).setText(item.getTimeData());
((TextView)view.findViewById(R.id.train_info)).setBackgroundColor(Color.parseColor("#cf9fe7"));
((TextView)view.findViewById(R.id.stations_info)).setBackgroundColor(Color.parseColor("#ddbcee"));
((AutoResizeTextView)view.findViewById(R.id.time_info)).setBackgroundColor(Color.parseColor("#cf9fe7"));
}
return view;
}
}
DataListFragment は次のようになります。
public class DataListFragment extends ListFragment {
CustomArrayAdapter mAdapter;
public CustomArrayAdapter getAdapter() {
return mAdapter;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setEmptyText("");
mAdapter = new CustomArrayAdapter(getActivity());
mAdapter.notifyDataSetChanged();
setListShown(true);
}
public void changeAdapter(CustomArrayAdapter adapter) {
mAdapter = adapter;
setListAdapter(adapter);
mAdapter.notifyDataSetChanged();
setListShown(true);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
}
}
newContent は空ではないと確信していますが、List は変更されておらず、空のままで、何も表示されません。これをどうするか?
UPD:プログラムが途中で停止することに成功しました
setListShown(true);
エラーなしで停止し、その後は何もしません。神秘的です...