安卓:ListFragment
来源:互联网 发布:普查数据库 英语 编辑:程序博客网 时间:2024/05/29 10:10
Fragment对应的布局文件
<span style="font-size:18px;"><?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" > <!-- android:id="@id/android:list" Fragment 继承的是ListFragment 那么 id 就要固定的 --> <ListView android:id="@+id/android:list" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout></span>
Fragment对应的逻辑代码文件
<span style="font-size:18px;">package com.example.day12_listfragment;import java.util.ArrayList;import java.util.List;import android.annotation.SuppressLint;import android.app.ListFragment;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;@SuppressLint("NewApi") public class Listfragment extends ListFragment{List<String> list;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {list=new ArrayList<String>();for(int i=0;i<10;i++){list.add("You are beautiful!"+" "+i);}ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,list);setListAdapter(adapter);View view=inflater.inflate(R.layout.list_fragment,container,false);return view;}@Overridepublic void onListItemClick(ListView l, View v, int position, long id) {super.onListItemClick(l, v, position, id);Toast.makeText(getActivity(),list.get(position), 0).show();}}</span>
主布局文件
<span style="font-size:18px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <fragment android:id="@+id/fg" android:name="com.example.day12_listfragment.Listfragment" android:layout_width="match_parent" android:layout_height="wrap_content" /></RelativeLayout></span>
主逻辑代码文件不需写代码
0 0
- 安卓:ListFragment
- ListFragment
- ListFragment
- listFragment
- ListFragment
- !!!!!安卓界面总是显示加载进度条的问题,没事别乱用ListFragment
- ListFragment实例
- Android ListFragment
- Messages ListFragment
- android Listfragment
- Android ListFragment
- ListFragment+CheckedTextView和ListFragment+CheckBox两种多选效果
- 【Android 开发教程】ListFragment
- ListFragment setDivider的问题
- Android ListFragment实例Demo
- Android ListFragment使用
- ListFragment的使用
- 使用ListFragment显示列表
- UITextView内容添加后,自动滚动到最后一行
- 查找目录下的所有文件中是否含有某个字符串 :正则表达式、find、grep、xargs、awk、sed等
- solrj正确的日志信息
- ML基石_3_TypesOfLearning
- Android 多媒体应用——MediaPlayer音频播放
- 安卓:ListFragment
- 学习Activiti工作流框架的API
- Servlet之Cookie相关操作
- OC分类(Category)的作用和注意事项
- 错误:类型List不带有参数;java中import导入问题
- 图像处理与计算机视觉 基础、经典以及最近发展
- XHTML(2)
- 数据结构之堆排序java实现
- Android 内存泄漏的原因