Android 音乐播放器的开发教程(十二)SQLite的使用及我的最爱歌曲的实现 ----- 小达

SQLite的使用及我的最爱歌曲的实现


       早上好~~~~各位,今天接着昨天的android上数据库SQLite的使用来说说,怎么在昨天的基础上,实现歌曲添加入我的最爱.先上理想的效果图,进入播放界面之后就可以点击爱心添加为最爱歌曲,并放入数据库,在我的最爱栏目也可以看的到,再次点击红心就可以取消我的最爱,丛数据库再拿出来(讲解的话,主要在代码的注释里面):



       先来实现点击主界面上的我的最爱后切换至我的最爱fragment,一个MyFavoriteFragment.java和一个fragment_favorite_layout.xml,先给出布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/music_list_layout"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="@drawable/bg_photo_01">

    <RelativeLayout
        android:id="@+id/top_layout"
        android:background="#00000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/favorite_fragment_to_main_fragment"                      //从我的最爱fragment回退到mainFragment的按钮,也就是那个箭头
            android:layout_width="wrap_content"                                                     
            android:layout_height="wrap_content"
            android:background="@drawable/img_actionitem_back"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="15pt"
            android:textColor="@color/tomato"
            android:text="我 的 最 爱"
            android:completionThreshold="1"
            android:layout_toEndOf="@id/favorite_fragment_to_main_fragment"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />


    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/top_layout">

        <ListView
            android:id="@+id/favorite_music_list"                   //用来显示歌曲列表的litView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="#ffff99c9"
            android:dividerHeight="2dp"
            android:drawSelectorOnTop="false"
            android:listSelector="@color/cornsilk">
        </ListView>
    </RelativeLayout>

</RelativeLayout>


     下面是MyFavoriteFragment.java的代码,需要注意的是要在MainActivity中implements相应的接口,并且重写对应的函数,还需要在MainFragment中加入相应的点击事件响应, 切换至MyFavoriteFragment, 在PlayFragment中显示那颗爱心的状态,后面也一并给出部分代码:

package com.example.dada.myapplication;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

public class MyFavoriteFragment extends Fragment {


    private OnFragmentInteractionListener mListener;

    public static MyFavoriteFragment newInstance() {
        MyFavor
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
《嘟嘟音乐》是我自己写的Android,若有不足之处请大家谅解 1.首页实现读取本地Music本地文件夹中的MP3文件然后放进listview里面 2.实现了用户的用户的登录注册页面,登录过后用户可以进行自己的信息修改,实现了服务器的数据交互问题 3.实现了管理员登录,使用的是与Tomcat服务器进行数据交互验证信息的正确性,我使用的是myeclipse进行布置的服务器信息,此时使用的是SQLserver 2008 数据库存储的管理员的信息,读取完以后然后返回到管理界面 4.在嘟嘟音乐的管理界面,我实现了策划菜单以及卡片式布局来管理普通用户信息,以及用户信息的增删改查。查询使用的是以UserId或者昵称迷糊查询的方式进行查询的。 5.我使用的SQL server2008 的数据库文件我已经全部导出了,大家可以自行进行导入 6.我使用的myeclipse的项目是Servlet进行的验证app管理员信息的邓丽,项目我已经全部导出。放在压缩包里面 7.我使用的是Android Studio,我把文件布局截图放在压缩包里面,还有几个需要注意的地方,特别的坑,尤其是大家需要注意build.gridle(app)这里面大家需要注册导包,你并且配置好自己的SDK。大家还需要注意就是Android的注册文件里面也需要注意,关于一些权限的问题 8.哈哈,大概的的就写到这里了,写的不好的地方大家多见谅,我也是在学习阶段,把自己的写的东西给大家贡献出来以供大家参考学习使用。我还在压缩包里面放置了视频演示的链接信息,大家可以看看。如果感觉写的不错的话,请好评哦。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值