0
我得到了一個我已經做出的音調列表,我設法讓他們進入一個列表,但現在我面臨的挑戰是允許用戶「觸摸並按住」來指定爲通知音。下面是來自MainActivity.java代碼:在一個listView中作爲(通知)鈴聲選擇soundclip?
import java.util.ArrayList;
import android.app.ListActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ListView;
public class MainActivity extends ListActivity {
private ArrayList<Sound> mSounds = null;
private SoundAdapter mAdapter = null;
static MediaPlayer mMediaPlayer = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerForContextMenu(getListView());
this.getListView().setSelector(R.drawable.selector);
//create a simple list
mSounds = new ArrayList<Sound>();
Sound s = new Sound();
s.setDescription("Anjels");
s.setSoundResourceId(R.raw.anjels);
mSounds.add(s);
s = new Sound();
s.setDescription("Aggro");
s.setSoundResourceId(R.raw.aggro);
mSounds.add(s);
s = new Sound();
s.setDescription("Axo");
s.setSoundResourceId(R.raw.axo);
mSounds.add(s);
s = new Sound();
s.setDescription("Basix");
s.setSoundResourceId(R.raw.basix);
mSounds.add(s);
s = new Sound();
s.setDescription("Bender");
s.setSoundResourceId(R.raw.bender);
mSounds.add(s);
mAdapter = new SoundAdapter(this, R.layout.list_row, mSounds);
setListAdapter(mAdapter);
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id){
Sound s = (Sound) mSounds.get(position);
MediaPlayer mp = MediaPlayer.create(this, s.getSoundResourceId());
mp.start();
}@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
}
我也有另外兩個java文件,一個是「聲類」,另一個是「聲音適配器」雖然我不認爲他們是相對於我的問題。
就這樣,你們知道,我花了幾周的時間才弄到這一點,因爲我還是一個在javaland的新生。任何幫助或例子在這裏都會很熱!地獄,如果你想爲我做這些工作,那就更加甜美了!
我不明白。你爲什麼拿出'ContextMenu'代碼? – codeMagic
對不起,我已經想出了這部分,現在已經更新之前問這個問題。 –
那麼你現在面臨的問題是什麼? – codeMagic