首先需要下什么文件等等,个人觉得都是不需要的,当然原理上也是可以行得通的。最简单的方式就是如下:
官网上是这样说的:
jQuery (http://jquery.org)
Install the jQuery ruble and reference it:
If you already have the jQuery bundle:
or
java代码引用上述控件
mOptionalTip = (AutoCompleteEmailEdit) findViewById(R.id.optional_tip);
mOptionalTip.init();
mOptionalTip.addTextChangedListener(mTextWatcher);
private TextWatcher mTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if (!TextUtils.isEmpty(s) && s.toString().trim().length() > 0) {
mOptionalTip.createCandidateEmail(s.toString().trim());
}
}
};
补充TextUtils.isEmpty(s)可以判断空字符串或是空,不能判断空格,s.toString().trim().length() > 0这句用来排除空格
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/url" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="url方式播放" /> <Button android:id="@+id/uri" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="uri方式播放" /> <Button android:id="@+id/stop" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="停止" /> </LinearLayout>
SdService.java
import java.io.File;
import android.os.Environment;
public class SdService
{
private static Boolean sdCardExist;
/**
* 获得sdcard
*
* @return
*/
public static String getSDPath()
{
File sdDirFile = null;
sdCardExist = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
if (sdCardExist)
{
sdDirFile = Environment.getExternalStorageDirectory();// 获取跟目录
return sdDirFile.toString();
} else
{
return "";
}
}
}
playService
package com.cat.test; import android.content.Context; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.net.Uri; import android.util.Log; public class playService { private static MediaPlayer mPlayer; /** 为url时 */ public static final int URLPLAY = 0; /** 为uri时 */ public static final int URIPLAY = 1; private static final String TAG = "playService"; public static void PlayMusic(Context context, String url, int play) { mPlayer = new MediaPlayer(); switch (play) { case URLPLAY: urlPlayMusic(url); break; case URIPLAY: Uri uri = Uri.parse(url); uriPlayMusic(uri, context); break; default: break; } } public static void stopMusic() { if (mPlayer != null) { /* 是否正在播放 */ if (mPlayer.isPlaying()) { // 重置MediaPlayer到初始状态 mPlayer.stop(); } } } private static void urlPlayMusic(String url) { try { Log.v(TAG, "urlPlayMusic-->" + url); // 重置MediaPlayer mPlayer.reset(); // 设置要播放的文件的路径 mPlayer.setDataSource(url); // 准备播放 mPlayer.prepare(); // 开始播放 mPlayer.start(); // 音乐播放完执行的操作 mPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub } }); } catch (Exception e) { // TODO: handle exception Log.v(TAG, "urlPlayMusic-->" + "播放失败"); } } private static void uriPlayMusic(Uri uri, Context context) { try { Log.v(TAG, "uriPlayMusic-->" + uri.toString()); mPlayer.reset(); /* 设置要播放的文件的路径 */ mPlayer.setDataSource(context, uri); /* 准备播放 */ mPlayer.prepare(); /* 开始播放 */ mPlayer.start(); mPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub } }); } catch (Exception e) { // TODO: handle exception Log.v(TAG, "uriPlayMusic-->" + "播放失败"); } } }
PlayMusicActivity.java
package com.cat.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class PlayMusicActivity extends Activity { /** Called when the activity is first created. */ private Button urlPlayButton; private Button uriPlayButton; private Button stopButton; private String playUrlString; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); urlPlayButton = (Button) findViewById(R.id.url); uriPlayButton = (Button) findViewById(R.id.uri); playUrlString = SdService.getSDPath() + "/test.mp3"; stopButton = (Button) findViewById(R.id.stop); OnClickListener playOnClickListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.url: playService.PlayMusic(PlayMusicActivity.this, playUrlString, playService.URLPLAY); break; case R.id.uri: playService.PlayMusic(PlayMusicActivity.this, playUrlString, playService.URIPLAY); break; case R.id.stop: playService.stopMusic(); break; default: break; } }; }; urlPlayButton.setOnClickListener(playOnClickListener); uriPlayButton.setOnClickListener(playOnClickListener); stopButton.setOnClickListener(playOnClickListener); } }