試圖掌握Java和Android想要幫助他們點擊一個按鈕後打開用戶瀏覽器的簡單任務。打開瀏覽器到網頁安卓應用
我一直在做最後兩天的教程,雖然它可能有幫助,如果我只是刺傷它並獲得反饋。在此先感謝您的幫助。
的main.xml:
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bgimage2">
>
<Button
android:id="@+id/goButton"
android:layout_width="150px"
android:layout_height="wrap_content"
android:text="@string/start"
android:layout_x="80px"
android:layout_y="21px"
>
</AbsoluteLayout>
GetURL.java:
package com.patriotsar;
import android.app.Activity;
import android.content.Intent;
import android.view.View.OnClickListener;
String url = "http://www.yahoo.com";
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(url);
i.setData(u);
public class patriosar extends Activity {
private Button goButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
goButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v){
try {
// Start the activity
startActivity(i);
} catch (ActivityNotFoundException e) {
// Raise on activity not found
Toast toast = Toast.makeText(context, "Browser not found.", Toast.LENGTH_SHORT);
}
}
});
}
}
那麼......問題是什麼?代碼是否工作?代碼是否失敗?怎麼了? – trutheality 2011-05-29 07:59:13
另外,擺脫'AbsoluteLayout'。該容器類已被棄用。使用別的東西。 – CommonsWare 2011-05-29 10:59:11
@trutheality代碼不會在模擬器中運行。我會確保在下一篇文章中發佈我的錯誤。 – Denoteone 2011-05-29 22:26:21