Viewpager 片段中的 Android 列表
我为每个页面设置了一个视图分页器和片段,但无法弄清楚如何在其中一个片段中显示列表,我尝试过的所有内容都已强制关闭,所以这就是我现在回到的内容有关
public class Extras extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.extras, null, false);
return V;
}
}
如何我的任何帮助可以将其变成一个简单的列表将不胜感激
===编辑===
最终结果
public class Extras extends ListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.getListView().setTextFilterEnabled(true);
this.setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.row, items));
this.setEmptyText(getString(R.string.loading));
}
static final String[] items = new String[] {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Toast.makeText(getActivity(), l.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
}
}
I have a viewpager set up and fragments for each page but can't figure out how to show a list inside one of the fragments everything i've tried has forced closed so here's what i'm back to right now
public class Extras extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.extras, null, false);
return V;
}
}
Any help on how i could turn that into a simple list would be greatly appreciated
===Edit===
Final Result
public class Extras extends ListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.getListView().setTextFilterEnabled(true);
this.setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.row, items));
this.setEmptyText(getString(R.string.loading));
}
static final String[] items = new String[] {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Toast.makeText(getActivity(), l.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ListFragment
you can use ListFragment