Button cannot be enabled for type

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;



public class ProjectActivity extends Activity{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button tut1 = (Button) findViewById(R.id.tutorial1);
        tut1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

            startActivity(new Intent("android.intent.action.TUTORIALONE"));

            }
        });

    }
}

Follow the youtube tutorial, but I'm getting errors on this line:

setContentView(R.layout.main);

"Button cannot be enabled for type"

I'm new to android dev, so I'm confused. Help!

+3
source share
5 answers

use this in your xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/tutorial1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" >
    </Button>

</LinearLayout>
0
source

move the cursor to "button" in your code and select "Import Button (android.widget)".

+1
source

, main.xml? - :

<Button android:text="Click me" android:id="@+id/tutorial1"
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
0

:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" />
0

: 1. android.R(, ) 2. 3.

0

All Articles