Android Dev 和本网站的新手。我创建了一个应用程序并且基础工作正常。我添加了一个声音按钮,它起作用了。我为早期版本的 android 创建了一个新应用程序,并且不小心将我的 Main Activity 文件拖到了新应用程序中,而不是复制它。当我把它拖回来时,它说我的进口没有使用。现在,我必须为其执行“导入”声明的声音不起作用。这是代码。
package com.offthericta.wiferemote;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.offthericta.wiferemote.R;
import com.offthericta.wiferemote.R.id;
import com.offthericta.wiferemote.R.layout;
import com.offthericta.wiferemote.R.menu;
import com.offthericta.wiferemote.R.raw;
public class MainActivity extends Activity {
private static final String TAG = "MyActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v(TAG, "Initializing sounds...");
final MediaPlayer mp = MediaPlayer.create(this, R.raw.blah);
Button Button03 = (Button)this.findViewById(R.id.Button03);
Button03.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "Playing sound...");
mp.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View v){}
public void disclaimerBTN (View v){
Toast.makeText(this, "FAILED: The remote object is not responding to this command",Toast.LENGTH_LONG).show();
}
}