I'm still really new at this, but this should hopefully be a simple question and answer. I'm trying to just make a button and I've done so in the layout manager. I'm trying to implement it in code, but MotoDev won't recognize the Button class that's part of the android.widget package. I imagine I just have to do something similar to an import but I can't track down what that is. Any help would be appreciated.
package com.androidbook.myfirstandroidapp;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.location.Location;
import android.location.LocationManager;
import android.graphics.drawable.ColorDrawable;
public class MyFirstAndroidApp extends Activity
{
private static final String DEBUG_TAG= "MyFirstAppLogging";
private MediaPlayer mp;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String myString = getResources().getString(R.string.hello);
int myColor = getResources().getColor(R.color.Red);
float myDimen = getResources().getDimension(R.dimen.textPointSize);
ColorDrawable myDraw = (ColorDrawable)getResources().getDrawable(R.drawable.redDrawable);
//Log.i(DEBUG_TAG, "Info about MyFirstAndroidApp");
setContentView(R.layout.buttons);
final Button basic_button = (Button) findViewById(R.id.basic_button);
}
public void callThisNumber()
{
Uri number = Uri.parse("tel:3045555555");
Intent dial = new Intent(Intent.ACTION_DIAL, number);
startActivity(dial);
}
public void forceError()
{
if(true)
{
throw new Error("Whoops");
}
}
public void playMusicFromWeb()
{
try
{
Uri file = Uri.parse("http://www.perlgurl.org/podcast/archives/podcasts/PerlgurlPromo.mp3");
mp = MediaPlayer.create(this, file);
mp.start();
}
catch(Exception e)
{
Log.e(DEBUG_TAG, "Player failed", e);
}
}
public void getLocation()
{
try
{
LocationManager locMgr = (LocationManager)getSystemService(LOCATION_SERVICE);
Location recentLoc = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.i(DEBUG_TAG, "loc: " + recentLoc.toString());
}
catch(Exception e)
{
Log.e(DEBUG_TAG, "Location Failed", e);
}
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
if(mp != null)
{
mp.stop();
mp.release();
}
super.onStop();
}
} // End Class