续上
续上
易水寒521 发表于2年前
续上
  • 发表于 2年前
  • 阅读 24
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

MusicListAdapter

 package com.anhui.music_player.adapter;
import java.util.List;
import com.anhui.music_player.R;
import com.anhui.music_player.model.Music;
import com.anhui.music_player.util.ToTime;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class MusicListAdapter extends BaseAdapter{
 ToTime time;
    private List<Music> listMusic;
    private Context context;
    public MusicListAdapter(Context context,List<Music> listMusic){
     this.context=context;
     this.listMusic=listMusic;
    }
 public void setListItem(List<Music> listMusic){
  this.listMusic=listMusic;
 }
 @Override
 public int getCount() {
  return listMusic.size();
 }
 @Override
 public Object getItem(int arg0) {
  return listMusic.get(arg0);
 }
 @Override
 public long getItemId(int position) {
  return position;
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  time=new ToTime();
  if(convertView==null){
   convertView=LayoutInflater.from(context).inflate(R.layout.musiclist_item, null);
  }
  Music m=listMusic.get(position);
  //音乐名
  TextView textMusicName=(TextView) convertView.findViewById(R.id.music_item_name);
  textMusicName.setText(m.getName().subSequence(0, m.getName().length()-4));
  
  //歌手
  TextView textMusicSinger=(TextView) convertView.findViewById(R.id.music_item_singer);
  textMusicSinger.setText(m.getSinger());
    //持续时间
  TextView textMusicTime=(TextView) convertView.findViewById(R.id.music_item_time);
  textMusicTime.setText(time.toTime((int)m.getTime()));
  return convertView;
 }
}

local_music

 package com.anhui.music_player.view;

import java.util.List;
import com.anhui.music_player.R;
import com.anhui.music_player.adapter.MusicListAdapter;
import com.anhui.music_player.model.Music;
import com.anhui.music_player.util.MusicList;
import com.anhui.music_player.view.setting.about;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
public class local_music extends Activity {
 ImageView back;
 MusicListAdapter mla;
 ListView lv;
 List<Music> list;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.local_music);
  back = (ImageView) findViewById(R.id.play_back);
  lv = (ListView) findViewById(R.id.lv);
  list=MusicList.getMusicData(this);
  mla = new MusicListAdapter(this,list);
  lv.setAdapter(mla);
  back.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    Intent intent = new Intent();
    intent.setClass(local_music.this,
      com.anhui.music_player.view.MainActivity.class);
    startActivity(intent);
   }
  });
  lv.setOnItemClickListener(new OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
     long arg3) {
    Intent intent = new Intent();
    intent.setClass(local_music.this,
      com.anhui.music_player.view.play.class);
    intent.putExtra("musicId_1", arg2);
    startActivity(intent);
   }
  });
 }
 // 菜单选项
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // menu.add(0,1,0,"退出"); //添加选项
  // menu.add(0,2,0,"关于"); //添加选项
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }
 @SuppressLint("ShowToast")
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  if (item.getItemId() == R.id.exit) {
   Intent intent = new Intent("com.sleep.close");
   sendBroadcast(intent);
   dialog();
  }
  if (item.getItemId() == R.id.about) {
   Intent intent1 = new Intent(local_music.this, about.class);
   startActivity(intent1);
  }
  return super.onOptionsItemSelected(item);
 }
 protected void dialog() {
  AlertDialog.Builder builder = new Builder(local_music.this);
  builder.setMessage("确定要退出吗?");
  builder.setTitle("提示");
  builder.setPositiveButton("确认",
    new android.content.DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
      // AccoutList.this.finish();
      // System.exit(1);
      android.os.Process.killProcess(android.os.Process
        .myPid());
     }
    });
  builder.setNegativeButton("取消",
    new android.content.DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
     }
    });
  builder.create().show();
 }}

local_music.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <RelativeLayout
        android:id="@+id/r1"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:background="#249EF6" >
        <ImageView
            android:id="@+id/play_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="5dp"
            android:src="@drawable/back" />
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/bflb1" />
    </RelativeLayout>
    <include
        android:id="@+id/ic"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentBottom="true"
        layout="@layout/bottom" 
        />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/r1"
        android:layout_above="@id/ic"
        android:background="#e3e3e3" >
        <ListView
            android:id="@+id/lv"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
    </RelativeLayout>
</RelativeLayout>

like

 package com.anhui.music_player.view;
import com.anhui.music_player.R;

public class like extends Activity {
 ImageView back;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.like);
  back=(ImageView) findViewById(R.id.play_back);
  back.setOnClickListener(new OnClickListener() {
   
   @Override
   public void onClick(View v) {
    Intent intent = new Intent();
    intent.setClass(like.this,
      com.anhui.music_player.view.MainActivity.class);
    startActivity(intent);
    
   }
  });
 }
 // 菜单选项
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {

  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }
 @SuppressLint("ShowToast")
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  if (item.getItemId() == R.id.exit) {
   Intent intent = new Intent("com.sleep.close");
   sendBroadcast(intent);
   dialog();
  }
  if (item.getItemId() == R.id.about) {
   Intent intent1 = new Intent(like.this, about.class);
   startActivity(intent1);
  }
  return super.onOptionsItemSelected(item);
 }
 protected void dialog() {
  AlertDialog.Builder builder = new Builder(like.this);
  builder.setMessage("确定要退出吗?");
  builder.setTitle("提示");
  builder.setPositiveButton("确认",
    new android.content.DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
      // AccoutList.this.finish();
      // System.exit(1);
      android.os.Process.killProcess(android.os.Process
        .myPid());
     }
    });
  builder.setNegativeButton("取消",
    new android.content.DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
     }
    });
  builder.create().show();
 } 
}

like.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <RelativeLayout
        android:id="@+id/r1"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:background="#249EF6" >
        <ImageView
            android:id="@+id/play_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="5dp"
            android:src="@drawable/back" />
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/like" />
    </RelativeLayout>
    <include
        android:id="@+id/ic"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentBottom="true"
        layout="@layout/bottom" 
        />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/ic"
        android:layout_below="@id/r1"
        android:background="#e3e3e3" >
        <ListView
            android:id="@+id/lv"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
    </RelativeLayout>
</RelativeLayout>

共有 人打赏支持
粉丝 0
博文 129
码字总数 120077
×
易水寒521
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: