总有坚持的理由 2016-09-07 14:07 采纳率: 37.5%
浏览 1948
已采纳

android在fragment中显示ListView!! 在线求~~

最近在做一个小项目 音乐APP播放器,用了不少在Activity中嵌入的Fragment
我想在fragment中使用ListView显示扫描到的本地音乐文件 懵逼了好久,求助....
怎么才能实现这个功能?
PS:在不使用ListFragment的情况下~~

  • 写回答

5条回答 默认 最新

  • 本人很懒zzz 2016-09-07 14:51
    关注

    先在layout文件夹下面创建一个fragment的xml布局文件,我建的是fragment_listview.xml:
    <?xml version="1.0" encoding="utf-8"?>
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    android:id="@+id/fragment_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    然后在自定义的Fragment中进行填充的操作:
    package com.example.test2;

    import android.os.Bundle;
    import android.support.annotation.Nullable;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ListView;

    public class MyFragment extends Fragment{

    private ListView lv;
    
    @Override
    public View onCreateView(LayoutInflater inflater,
            @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    
        View view=inflater.inflate(R.layout.fragment_listview, null);
        lv = (ListView) view.findViewById(R.id.fragment_content);
    
    
        /*
         * 这样布局文件填充到Fragment中,ListView也实例化好了。就可以进行你想要的操作了。
         */
    
    
        return view;
    }
    

    }

    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog