在Fragment里面实现listView布局
来源:互联网 发布:数据分析建模方法 编辑:程序博客网 时间:2024/06/01 16:37
这是布局文件fragment_haoyou.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!--首页--> <RelativeLayout android:id="@+id/shouye_shouyelayout" android:layout_width="match_parent" android:layout_height="35dip" android:background="@color/zhujiemianbeijing" > <Button android:layout_centerVertical="true" android:layout_width="25dip" android:layout_height="20dip" android:background="@mipmap/fanhuijiantou" /> <ImageView android:id="@+id/haoyou_guanzhufensi" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/haoyou_select" /> <Button android:layout_width="25dip" android:layout_height="25dip" android:background="@mipmap/cirun" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_marginRight="10dp"/> </RelativeLayout> <ListView android:id="@+id/haoyou_list" android:layout_width="fill_parent" android:layout_height="fill_parent"> </ListView></LinearLayout>以及item_haoyou.xml文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:id="@+id/item" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/tv_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="asdasdasd" /> <TextView android:id="@+id/tv_age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="asdasdasdssssssssssssssss" /></RelativeLayout>然后再是JAVA文件,这里我用的
public class Fragmenthaoyou extends Fragment implements View.OnClickListener,AdapterView.OnItemClickListener,AbsListView.OnScrollListener{ private ImageView image; private boolean temp=true; // View view2; private ListView haoyouListview; private List<Map<String, Object>> dataList; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_haoyou,container,false); view2 = inflater.inflate(R.layout.item_haoyou, null); initlist(view,inflater, container); init(view); return view; } private void init(View view) { image = (ImageView) view.findViewById(R.id.haoyou_guanzhufensi); image.setOnClickListener(this); } private void initlist(View view,LayoutInflater inflater,ViewGroup container) { haoyouListview = (ListView) view.findViewById(R.id.haoyou_list); SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), getData(), R.layout.item_haoyou, new String[]{"pic", "text"}, new int[]{R.id.tv_name, R.id.tv_age}); haoyouListview.setAdapter(simpleAdapter); haoyouListview.setOnItemClickListener(this); haoyouListview.setOnScrollListener(this); } private List<? extends Map<String, ?>> getData() { dataList = new ArrayList<Map<String, Object>>(); Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("pic", R.mipmap.ic_launcher); map1.put("text", "个人中心"); dataList.add(map1); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("pic", R.mipmap.ic_launcher); map2.put("text", "宝贝中心"); dataList.add(map2); for (int i = 0; i < 20; i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("pic", R.mipmap.ic_launcher); map.put("text", "爱你全家a "); dataList.add(map); } return dataList; } @Override public void onClick(View view) { switch (view.getId()){ case R.id.haoyou_guanzhufensi: Data(); } } @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { switch (position) { case 0: Toast.makeText(getActivity(), "进入个人中心", Toast.LENGTH_SHORT).show(); break; case 1: Toast.makeText(getActivity(), "进行宝贝中心", Toast.LENGTH_SHORT).show(); break; } } @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int i, int i1, int i2) { } private void Data() { if(temp) { image.setSelected(temp); temp =false; } else{ image.setSelected(temp); temp = true; } }}
0 0
- 在Fragment里面实现listView布局
- 在activity里面实现fragment管理
- 安卓在fragment里面使用TabHost布局
- 点赞动画在listview里面实现
- 在fragment里面嵌套fragment
- 在Fragment里面使用ExpandableListView实现仿qq好友列表
- Fragment里面listview在头部嵌套gridview无限刷新错误解决
- fragment里面添加listview的问题
- 在 fragment 里面调用 findViewById
- 在 fragment 里面调用 findViewById
- 在 fragment 里面调用 findViewById
- fragment+viewpager实现布局
- android中在fragment A里面点击button跳转到fragment B怎么实现?
- fragment切换导致fragment里面的listView不显示
- 想实现在ListFragment里面的ListView的item里面的Button的点击事件
- 想实现在ListFragment里面的ListView的item里面的Button的点击事件
- Fragment对于Listview未满一屏添加脚布局,满屏将View固定在屏幕下方的解决方案
- ListView镶嵌在ScrollView里面
- JSP有哪些内置对象和动作?它们的作用分别是什么?
- 【图书分配】
- android不让程序显示在最近程序列表中
- strcpy 溢出问题
- pin导致路由器死掉的解决方法
- 在Fragment里面实现listView布局
- Innodb的复制发布
- Mini模块构件
- 超详细!ActionBar 使用·详解
- 图(最小生成树) MST 2
- 沟通理解的不易
- SOCKET原理
- UITableView 滚动时,显示隐藏UINavigaionbar的方法
- jQuery下的瀑布流效果(改)