Android3.0后出来的新控件,主要是为了在平板和手机屏幕的兼容

实现效果:

点击Sd卡,出现SD目录下的所有文件和文件夹,点击外置Sd卡,出现外置Sd卡目录下的文件和文件夹.点击U盘,出现U盘目录下所有文件和文件夹。

实现如上图的效果,左边点击SD卡,右边显示gridView的内容,需要定义一个主Activity,main.xml中定义好布局,如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<LinearLayout
        android:id="@+id/root"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        >
    </LinearLayout>

<LinearLayout
        android:id="@+id/content"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>
 
</LinearLayout>

Activity中加载方式:

private FragmentManager manager;
private FragmentTransaction transacion;

manager = getFragmentManager();
transacion = manager.beginTransaction();
rootfragment root = new rootfragment();
contentfragment content = new contentfragment();

transacion.add(R.id.root, root,"root");
transacion.add(R.id.content,content,"content");
transacion.commit();

接着定义左边和右边的fragment,先定义左边布局文件的内容,在rootfragment.java中进行加载,

public class rootfragment extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment_root, null);
}

}

同样的方式加载右边显示的内容,接着需要将两个fragment之间进行数据的传递:

contentfragment details = (contentfragment)getFragmentManager().findFragmentByTag("content");

获取到右边的fragment,通过该对象就可以将数据传递给contentfragment类,操作contentfragment里面的函数。这里需要传递文件路径给contentfragment,再让contentfragment进行刷新显示就可以了

fragment的实现与互相通信的更多相关文章

  1. Fragment与Activity之间的通信

      我个人将Fragment与Activity间的通信比喻为JSP与Servlet间的通信,fragment中用接口的方式来进行与Activity的通信.通信的结果可以作为数据传入另一个Fragmen ...

  2. Android系列之Fragment(三)----Fragment和Activity之间的通信(含接口回调)

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  3. 适配器(adapter)与fragment之间、fragment与activity之间的通信问题

    一.适配器(adapter)与fragment之间通信 通过本地广播进行通信 步骤如下 在adapter中代码 声明本地广播管理 private LocalBroadcastManager local ...

  4. Fragment 与Activity之间的通信

    1.Fragment-->Activity 在fragment中的onAttach()中引用Activity实现的接口实例. 2Activity-->Fragment 直接调用 3多个Fr ...

  5. Android -- TabHost、Fragment、状态保存、通信

    工程结构                                                                                       TabAFm到Ta ...

  6. Android -- ViewPager、Fragment、状态保存、通信

    工程架构                                                                                      TabAFm到Tab ...

  7. Fragment和activity之间的通信

    1>fragment可以调用getactivity()方法获取它所在的activity. 2>activity可以调用FragmentManager的findFragmentById()或 ...

  8. Fragment间的通信

    在网上看到的一篇文章,总结的很好 为了重用Fragment的UI组件,创建的每个Fragment都应该是自包含的.有它自己的布局和行为的模块化组件.一旦你定义了这些可重用的Fragment,你就可以把 ...

  9. Fragment之间的通信

    在本节中,你会学到 1.定义接口 2.实现接口 3.将消息传递给fragment 为了重用Fragment UI 组件,在设计中你应该通过定义每一个fragemnt自己的layout和行为,让frag ...

随机推荐

  1. Gridview实现银行选择列表

    [MainActivity.java] package com.example.activitydemo; import android.os.Bundle; import android.view. ...

  2. HDOJ 1787 GCD Again(欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. PHP Ctype函数(转)

    Ctype函数是PHP内置的字符串体测函数.主要有以下几种 ctype_alnum -- Check for alphanumeric character(s)检测是否是只包含[A-Za-z0-9] ...

  4. is not in the sudoers file.This incident will be reported

    解决方法如下: 1>.进入超级用户模式.也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式. 2>.添加文件的写权限.也就是输入命令&q ...

  5. Android(java)学习笔记226:服务(service)之为什么使用服务

    1.服务 service 长期在后台运行的进程,一般没有应用程序界面   2.进程线程和应用程序之间的关系 应用程序开启,系统启动一个Linux进程,所有的组件都是运行在同一个进程的同一个线程(mai ...

  6. Python Socket通信原理

    [Python之旅]第五篇(一):Python Socket通信原理   python Socket 通信理论 socket例子 摘要:  只要和网络服务涉及的,就离不开Socket以及Socket编 ...

  7. WearableListView的使用和一些思考

    今年加盟了一家做手表的公司,至此开启了androidwear(类)的开发之门. 近日要做一个手表上的List显示,为此也是花了很多的心思在List效果上,多日下来,有些心得. 一.需求确定: 手表上的 ...

  8. scn转换为十进制

  9. 【转】UITextView 修改键盘 的return按钮

    原文:http://www.apkbus.com/blog-107838-45740.html 1 #import <UIKit/UIKit.h>2 3 @interface TextVi ...

  10. Java数据库连接池的几种配置方法(以MySQL数据库为例)

    Java数据库连接池的几种配置方法(以MySQL数据库为例) 一.Tomcat配置数据源: 前提:需要将连接MySQL数据库驱动jar包放进Tomcat安装目录中common文件夹下的lib目录中 1 ...