最近在做一个小项目 音乐APP播放器,用了不少在Activity中嵌入的Fragment
我想在fragment中使用ListView显示扫描到的本地音乐文件 懵逼了好久,求助....
怎么才能实现这个功能?
PS:在不使用ListFragment的情况下~~
android在fragment中显示ListView!! 在线求~~
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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; }
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
- ¥15 fluent的在模拟压强时使用希望得到一些建议
- ¥15 STM32驱动继电器
- ¥15 Windows server update services
- ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
- ¥15 模糊pid与pid仿真结果几乎一样
- ¥15 java的GUI的运用
- ¥15 Web.config连不上数据库
- ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
- ¥15 怎么配置广告联盟瀑布流