当前位置: 代码迷 >> Android >> android 添加onclicklistener后就出有关问题
  详细解决方案

android 添加onclicklistener后就出有关问题

热度:20   发布时间:2016-05-01 21:32:12.0
android 添加onclicklistener后就出问题
package com.android.dbs;

import android.app.Activity;
//import android.content.DialogInterface;
//import android.content.DialogInterface.OnClickListener;
//import android.view.View;
//import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
//import android.widget.ListAdapter;

public class DanceDemoActivity extends Activity {
   
Button btn_music;

/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  init();
  setContentView(R.layout.main);
   
  }
   
  public View.OnClickListener musicOnClickListener = new View.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(DanceDemoActivity.this, MusicList.class);
startActivity(intent);
}
 
  };
   
  public void init(){
  btn_music = (Button) this.findViewById(R.id.btn_game_music);
  btn_music.setOnClickListener(musicOnClickListener);
  }
}


------------------------------------------------------------------


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/RelativeLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/main_1"
  android:orientation="vertical" >


  <Button
  android:id="@+id/btn_game_start"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_alignParentTop="true"
  android:layout_marginLeft="22dp"
  android:layout_marginTop="43dp"
  android:text="@string/game_start" />



  <Button
  android:id="@+id/btn_game_music"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/btn_game_start"
  android:layout_below="@+id/btn_game_start"
  android:text="@string/game_music" />



  <Button
  android:id="@+id/btn_game_background"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/btn_game_music"
  android:layout_below="@+id/btn_game_music"
  android:text="@string/game_background" />




  <Button
  android:id="@+id/btn_game_about"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignLeft="@+id/btn_game_background"
  android:layout_alignRight="@+id/btn_game_background"
  android:layout_below="@+id/btn_game_background"
  相关解决方案