[英]Custom ListView in ViewPager Fragment
I have a ViewPager
using Fragments. 我有一个使用片段的
ViewPager
。 The ListView
is working with the default setting, but how do I use a custom ListView
(font size + image)? ListView
使用默认设置,但是如何使用自定义ListView
(字体大小+图像)?
My code so far: 到目前为止,我的代码:
public class Page2Fragment extends Fragment {
Button btnWrite;
public String ptext="..PAGE 2..";
private String arry[] = { "Tofeeq", "Ahmad", "Fragment", "Example",
"Tofeeq", "Ahmad", "Fragment", "Example" };
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
// fragment not when container null
if (container == null) {
return null;
}
// inflate view from layout
View view = (LinearLayout)inflater.inflate(R.layout.page2,container,false);
// update text
TextView tv = (TextView) view.findViewById(R.id.tvText2);
tv.setText(ptext);
ListView listView = (ListView) view.findViewById(R.id.listView1);
ArrayAdapter<String> array = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1);
for (String str : arry)
array.add(str);
listView.setAdapter(array);
return view;
}
// set text helper function
public void setText(String item) {
TextView view = (TextView) getView().findViewById(R.id.tvText2);
view.setText(item);
}
}
使用@android:id / text1等为每个项目创建自己的布局。完成此xml布局后,将android.R.layout.simple_list_item_1替换为R.layout。[您的布局名称]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.