我正在尝试使用片段在列表视图中显示基本的标题数组。而且无法让List项目显示出来。想知道是否有人可以解释一下。还有什么好的资源可以帮助你理解布局吗?
这是我的list_fragment.xml和listfragment源文件
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@id/android:list"
android:drawSelectorOnTop="false"
android:layout_weight="1"
android:layout_height="0dp"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
public class PublicTradeListFragment extends ListFragment
{
private String trades[];
public PublicTradeListFragment()
{
trades = new String [] {
"Trade ?",
"Give up ?",
"Trade again?"
};
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
ListAdapter listAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,trades);
setListAdapter(listAdapter);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.list_fragment,container,false);
}
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
Toast.makeText(getActivity(), getListView().getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:0)
您可以在&#34;创建视图&#34;中尝试此操作。然后 &#34;返回super.onCreateView(inflater,container,savedInstanceState);&#34;
点击此链接:http://wptrafficanalyzer.in/blog/a-listfragment-application-in-android/