RadioGroupDemo
btn_Group = (RadioGroup) findViewById(R.id.friut);
btn_apple = (RadioButton) findViewById(R.id.apple);
btn_banana = (RadioButton) findViewById(R.id.banana);
btn_peach = (RadioButton) findViewById(R.id.peach);
Title = (TextView) findViewById(R.id.text);
Result = (TextView) findViewById(R.id.result);
btn_Group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
// int id=group.getCheckedRadioButtonId();
switch(checkedId){
case R.id.apple:
Result.setText("你选择的是"+btn_apple.getText());
break;
case R.id.banana:
Result.setText("你选择的是"+btn_banana.getText());
break;
case R.id.peach:
Result.setText("你选择的是"+btn_peach.getText());
break;
}
}
});
音乐播放器
很粗糙的播放器,还在修改中
private SeekBar pb;
public static int currentSongIndex = 0;
private boolean isShuffle = false;
private boolean isRepeat = false;
public static final int player=1;
public static final int playlist=2;
public static final int settings=3;
public static int ViewState=0;
public ImageView pl;
public ArrayList<HashMap<String, Object>> songList = new ArrayList<HashMap<String, Object>>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
final TabHost th = (TabHost) findViewById(R.id.tabhost);
bt_Next = (ImageButton) findViewById(R.id.next);
bt_Play = (ImageButton) findViewById(R.id.play);
bt_Previous = (ImageButton) findViewById(R.id.previous);
bt_Repeat=(ImageButton)findViewById(R.id.repeat);
bt_Shuffle=(ImageButton)findViewById(R.id.shuffle);
pl=(ImageView)findViewById(R.id.imageView1);
pl.setAlpha(100);
SongTitle=(TextView)findViewById(R.id.songTitle);
songCurrentDurationLabel=(TextView)findViewById(R.id.currentTime);
songTotalDurationLabel=(TextView)findViewById(R.id.totalTime);
pb = (SeekBar) findViewById(R.id.seekbar);
mp = new MediaPlayer();
SongManager sm = new SongManager();
utils = new Utilities();
pb.setOnSeekBarChangeListener(this);
mp.setOnCompletionListener(this);
songList = sm.getSongList();
playSong(0);
// set the tabhost view
th.setup();
th.addTab(th.newTabSpec("tab1")
.setIndicator("歌曲", getResources().getDrawable(R.drawable.bg0))
.setContent(R.id.ll_0));
th.addTab(th
.newTabSpec("tab2")
.setIndicator("播放列表",
getResources().getDrawable(R.drawable.bg1))
.setContent(R.id.ll_1));
th.addTab(th.newTabSpec("tab3")
.setIndicator("设置", getResources().getDrawable(R.drawable.bg1))
.setContent(R.id.ll_2));
// put the data from sdcard into list
ListAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.list_item, new String[] { "songTitle","songTime" },
new int[] { R.id.songTitle ,R.id.songTime});
setListAdapter(adapter);
ListView lv = getListView();
// listening to single listitem click
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
currentSongIndex = position;
playSong(currentSongIndex);
th.setCurrentTab(0);
ViewState=player;
}
});