creating app buttons to open the browser
I attempted to work with a code set for a learning project as shown below however it keeps throwing back errors for R.layout.main. Also, should I add my own own icons or do I simply let the SDK use the defaults?
1)manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity
android:name=".todolist"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2).java
package com.tutorial.todolist;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class todolist extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.btn_clickme);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
I开发者_运维知识库ntent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://www.anddev.org"));
startActivity(myWebLink);
}
});
}
}
3).main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="schemas.android.com/apk/res/android";
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/btn_clickme"
android:text="Click me..."
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Remove the semicolon (;) in the first line of LinearLayout
xmlns:android="schemas.android.com/apk/res/android"
try changing in main.xml this:
xmlns:android="schemas.android.com/apk/res/android";
to
xmlns:android="http://schemas.android.com/apk/res/android";
though i am not sure if it will help....
<intent-filter>
<action android:name"android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"/>
</intent-filter>
Add this one to your manifest and try again.
精彩评论