續上

MusicListAdapterjava

 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_musicandroid

 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.xmlapp

 <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>

likeide

 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.xmlui

 <?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>
相關文章
相關標籤/搜索