开发者

stuck on first simple android app

Long time Android user first time developer. I am trying to simply set up the fist action of my app which is two buttons one will open the browser and send the user to a URL the other will open a page that gets XML data from a url and shows the value of one node.

BUT FOR NOW I JUST WANT TO KNOW WHY I AM GETTING THE FOLLOWING ERROR:

Description Resource    Path    Location    Type
The type new View.OnClickListener(){} must implement the inherited abstract method View.OnClickListener.onClick(View)   patriosar.java  /com.patriotsar/src/com/patriotsar  line 27 Java Problem

JAVA:

package com.patriotsar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.TextView;


public class patriosar extends Activity {

     private Button startButton;
     private Button subscribe;

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

        this.findAllViewsById();

        startButton.setOnClickListener(new OnClickListener() {            

        });

        subscribe.setOnClickListener(new OnClickListener() {            

        });

        private void findAllViewsById() {
            start = (Button) findViewById(R.id.startbutton);
            subscribe = (Button) findViewById(R.id.subscribe);
        }

    }
}

MAIN.XML

<?xml version="1.0" encoding="utf-8"?>

<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/startButton"
android:layout_width="150px"
android:layout_height="wrap_content"
android:text="@string/start"
android:layout_x="80px"
android:layout_y="21px"
>
</Button>

<Butt开发者_Go百科on
android:id="@+id/subscribe"
android:layout_width="150px"
android:layout_height="wrap_content"
android:text="@string/subscribe"
android:layout_x="80px"
android:layout_y="74px"
>
</Button>

<TextView
  android:id="@+id/textview"
  android:layout_width="300px"
  android:layout_height="fill_parent"
  android:text="@string/intro"
  android:layout_y="300px"
  android:layout_x="20px"
  android:textColor="#ffffff"
  />
</AbsoluteLayout>

I know it doesnt do anything but not sure why I am already getting errors. Any help would be awesome


You need an onClick() method inside each listener:

    startButton.setOnClickListener(new OnClickListener() {            
        public void onClick(View v) {
            ...do stuff...
        }
    });


You can either implement :

startButton.setOnClickListener(new View.OnclickListener(){ 
  public void onClick(){
  // do your thing
  } 
}

or you can do :

startButton.setOnclickListener(this);

 public void onClick(){
   switch(id){
     case R.id.startbutton : //do your thing
      break;
     case R.id.subscribe : //do your thing
      break;
  }

}

You need to implements OnclickListener to your activity, but if you have Eclipse, it's automatic .


apart from onClick, you can implement View.OnClickListener after extending Activity and implement onclick() method.

If you use eclipse, it will guide you through errors !


You just have to implement the onClick() inside your onClickListeners

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜