編輯:關於android開發
<?xml version="1.0" encoding="utf-8"?>
<!-- 定義當前布局的基本LinearLayout -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- 定義提示用戶播放mp3的顯示控件 -->
<TextView
android:id="@+id/Tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="點擊按鈕播放/sdcard/1.mp3文件"
/>
<!-- 定義用戶點擊播放聲音的按鈕控件 -->
<Button
android:id="@+id/Btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="播放聲音"
/>
</LinearLayout>
package com.example.yanlei.yl2;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// 定義布局中的播放聲音的Button控件
private Button btn;
// 定義顯示標簽的控件
private TextView Tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//設置當前Activity的布局文件為activity_main
setContentView(R.layout.activity_main);
//得到浏覽器中的控件對象
findView();
//設置對象的監聽器
setListener();
}
private void setListener() {
// 設置btn的點擊監聽器
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//定義intent對象,設置action屬性為Intent.ACTION_VIEW
Intent it = new Intent(Intent.ACTION_VIEW);
//定義sdcard下的song.mp3文件的uri
Uri uri = Uri.parse("file:///sdcard/1.mp3");//不是內存卡
//設置intent的數據類型為audio/mp3,這樣就可以啟動系統程序打開mp3文件了
it.setDataAndType(uri, "audio/mp3");
//通過intent打開activity
startActivity(it);
}
});
}
private void findView() {
// 得到布局中的開始加載的Button的對象
btn = (Button) findViewById(R.id.Btn);
// 得到布局中的開始加載的EditText的對象
Tv = (TextView) findViewById(R.id.Tv);
}
}
快速排序的離散數學分析,排序離散數學分析
快速排序的離散數學分析,排序離散數學分析 下面是偽代碼,這裡為了效率更高效,把切分值改成隨機化,算法原碼請參考 算法-5.快速排序 QUICKSO
Android----Thread+Handler 線程 消息循環(轉載),handlerthread
Android----Thread+Handler 線程 消息循環(轉載),handlerthread近來找了一些關於android線程間通信的資料,整理學習了一下,並制
Android進程通信之兩種序列化方式分析
Android進程通信之兩種序列化方式分析 2月下旬辭職了,去海南度假到現在,領略了一把三亞風情也算任性和 然而這樣任性帶來的後果就是。。不行了我必須吐槽一句。。 沒
Android學習指南之二十七:如何使用Handler
當用戶點擊一個按鈕時如果執行的是一個常耗時操作的話,處理不好會導致系統假死,用