I'm quite a newbie for the eclipse, and I've just started to write some code (actually it's just copy and paste from the website). Can anyone help me about this?
The error is appeared on the R.id.toggleButton1
, I had added the line
android:id="@+id/toggleButton1"
in my layout activity_main.xml
, but the error is still there :(
The error was:
toggleButton1 cannot be resolved or is not a field
The java source:
package com.example.ledgo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends Activity {
ToggleButton tgbutton;
private Activity activity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity = this;
tgbutton = (ToggleButton) findViewById(R.id.toggleButton1);
tgbutton.setOnClickListener(new OnClickListener() {
...
The code for my layout xml or called activity_main:
<?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="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
...