告诉我我做错了什么?
我正在尝试填写表格。但是数据没有出现在 ListView 中。
例如,在 Activity 中它正在工作。正是这段代码没有尝试过,而是从它完美运行的地方复制而来。
数据准确,经过调试器检查。
public class TabFilter extends Fragment {
private static String TAB_FILTER_LOG = "TabFilter: ";
private ArrayList<HashMap<String, Object>> filterListData;
private ListView filterListView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.tab_filter, container, false);
filterListView = (ListView) view.findViewById(R.id.filtersListView);
filterListData = new ArrayList<HashMap<String, Object>>();
fillListView();
SimpleAdapter filtersListAdapter = new SimpleAdapter(getActivity().getBaseContext(), filterListData, R.layout.filters_list_view_row, new String[] { "name",
"nummer" }, new int[] { R.id.filterNameTv, R.id.filterInfoTv });
filterListView.setAdapter(filtersListAdapter);
filterListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// filterListView.setOnItemClickListener(this);
if (container == null) {
return null;
}
return (LinearLayout) inflater.inflate(R.layout.tab_filter, container, false);
}
private HashMap<String, Object> fillListView() {
HashMap<String, Object> fillMap = null;
SQLiteDatabase db = DatabaseHelper.getInstance(getActivity().getBaseContext()).getWritableDatabase();
Cursor cursor = db.query("filters", null, null, null, null, null, null);
if (cursor.moveToFirst()) {
int nameColIndex = cursor.getColumnIndex("name");
int nummerColIndex = cursor.getColumnIndex("nummer");
do {
fillMap = new HashMap<String, Object>();
fillMap.put("name", cursor.getString(nameColIndex));
fillMap.put("nummer", cursor.getString(nummerColIndex));
filterListData.add(fillMap);
} while (cursor.moveToNext());
cursor.close();
db.close();
} else {
Toast.makeText(getActivity().getBaseContext(), "0 ROWS: ", Toast.LENGTH_LONG).show();
}
return fillMap;
}
}
tab_filter.xm
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/filtersListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
filters_list_view_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/BlueViolet">
<TextView
android:id="@+id/filterNameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@color/LightGrey"/>
<TextView
android:id="@+id/filterInfoTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/LightSkyBlue" />
</LinearLayout>