我在這方面還很新,但這應該是一個簡單的問題和答案。我試圖只做一個按鈕,而且我在佈局管理器中這樣做了。我試圖在代碼中實現它,但MotoDev不會識別屬於android.widget包的Button類。我想我只需要做一些類似於導入的東西,但我無法追查那是什麼。任何幫助,將不勝感激。MotoDev不識別Button類?
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
我試過了,它不會允許它,因爲它是一個包。感謝您的幫助。至少我知道我並不是唯一一個認爲導入應該修復它的人。 – Geeklat 2010-10-16 13:20:38
如何android.widget。*; – Eliseo 2010-10-20 14:38:54