如何使用列表适配器使用歌曲标题,艺术家,持续时间和数据填充列表视图

时间:2015-09-25 00:59:30

标签: android

我正在制作一个简单的音乐播放器。

此方法以字符串数组的形式返回设备上所有歌曲的标题。

<?php
include "../get/header.php";
$Username = SecurePost($_GET['Username']);
$gU = mysqli_fetch_object($getUser = mysqli_query($connection, "SELECT * FROM Users WHERE Username='".$Username."'"));
$UserExist = mysqli_num_rows($getUser = mysqli_query($connection, "SELECT * FROM Users WHERE Username='".$Username."'"));
$getUsers = mysqli_query($connection, "SELECT * FROM Users");
$numUsers = mysqli_num_rows($getUsers); 
$reqKills = mysqli_num_rows($allKills = mysqli_query($connection, "SELECT * FROM Kills WHERE Killer='".$gU->Username."'")); 
mysqli_query($connection, "UPDATE Users SET Kills='".$reqKills."' WHERE Username='".$gU->Username."'");
$pID = file_get_contents('http://rproxy.pw/rapi/GetIdByUsername/'.$gU->Username.'');
$Rank = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRole&playerid='.$pID.'&groupid=947351');

$getTemp = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='983872'");
$numTemp = mysqli_num_rows($getTemp); 

$Tact = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='976897'");
$numTac = mysqli_num_rows($Tact); 

$Sci = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='986292'");
$numSci = mysqli_num_rows($Sci); 

$MAC = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='1045203'");
$NumMAC = mysqli_num_rows($MAC); 

$Ops = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='1159559'");
$numOps = mysqli_num_rows($Ops); 

$Eng = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='990439'");
$numEng = mysqli_num_rows($Eng); 

$Diplo = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='992455'");
$numDip = mysqli_num_rows($Diplo); 

$Intel = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='974799'");
$numIntel = mysqli_num_rows($Intel); 

$realIA = mysqli_query($connection, "SELECT * FROM Branchs WHERE Username='".$Username."' AND GroupID='2640969'");
$numIA = mysqli_num_rows($realIA); 
#GroupAssign#
$Temporal = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=983872');
$Tactical = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=976897');
$Science = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=986292');
$MACO = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=1045203');
$Operations = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=1159559');
$Engineering = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=990439');
$IA = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=2640969');
$Diplomatic = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=992455');
$Intelligence = file_get_contents('http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=IsInGroup&playerid='.$pID.'&groupid=974799');

if ($Temporal == true AND $numTemp == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Temporal Investigations','Temporal','983872')");
}
if ($Tactical == true AND $numTac == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Tactical Command','Tactical','976897')");
}
if ($Science == true AND $numSci == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Applied Sciences','Science','986292')");
}
if ($MACO == true AND $NumMAC == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','MACO','MACO','1045203')");
}
if ($Operations == true AND $numOps == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Operations','Operations','1159559')");
}
if ($Engineering == true AND $numEng == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Engineering','Engineering','990439')");
}
if ($IA == true AND $numIA == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Internal Affairs','IA','2640969')");
}
if ($Diplomatic == true AND $numDip == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Diplomatic Corps','Diplomatic','992455')");
}
if ($Intelligence == true AND $numIntel == "0") {
mysqli_query($connection, "INSERT INTO Branchs (Username, Name, Image, GroupID) VALUES('".$gU->Username."','Starfleet Intelligence','Intelligence','974799')");
}
?>

将字符串数组传递给适配器,该适配器填充列表视图。

private String[] getMusic() {

        String[] projection = {
                MediaStore.Audio.Media.TITLE,
        };

        final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                projection, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];
        int i = 0;
        if (mCursor.moveToFirst()) {
            do {
                songs[i] = mCursor.getString(0);
                i++;
            } while (mCursor.moveToNext());
        }

        mCursor.close();

        return songs;
    }

如何使用列表适配器包含艺术家,持续时间和数据?

例如,我的mMusicList = getMusic(); ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, mMusicList); mListView.setAdapter(mAdapter); 方法可以这样开始:

getMusic()

我无法弄清楚剩下的。也许歌曲数组可以在传递给适配器之前制作成多维的,例如。

private String[] getMusic() {

        String[] projection = {
                MediaStore.Audio.Media.ARTIST,
                MediaStore.Audio.Media.TITLE,
                MediaStore.Audio.Media.DATA,
                MediaStore.Audio.Media.DURATION
        };

        ...

    }

1 个答案:

答案 0 :(得分:0)

您应该创建一个自定义适配器并将其传递给您的数据,这些数据将以自定义布局显示,您也应该创建它。 web中有很多例子。