我有一个应用程序,其中有几个选项卡;与任何人交互都会调用要显示的片段。不幸的是,当我切换到下面的片段时,我的 listView 没有出现,尽管有问题的列表已被填充。非常感谢您提供的任何帮助。
片段的相关代码:
public class Fragment_1 extends SherlockFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
//If time permits, I will try to make a Custom Adapter implemented with a TreeSet
TreeSet<BlacklistWord> theSet = MainActivity.getInstance().datasource.GetAllWords();
ArrayList<String> list = new ArrayList<String>();
for(BlacklistWord i :theSet){
System.out.println(i.getWord());
list.add(i.getWord());
}
Collections.sort(list);
//Making BlackList
listView = new ListView(getActivity());
listView.findViewById(R.id.listview);
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter);
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
container.addView(listView);
return inflater.inflate(R.layout.blacklist, container, false);
// return inflater.inflate(R.layout.blacklist, container, false);
}
}
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" >
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>