Java – event handler in Android – designer time automation and handling 2 views in a separate handler

I am a novice in eclipse (Indigo) and Android. I come from visual studio 2010 and C #

>In VS, when I double-click an event in the designer (for example, click the button class), VS2010 creates its own handler method and registers it in the event How can I do this during an eclipse? Link here shows the result I want, but it's not like that > suppose I have two buttons, how can I set different event handlers for each button instead of anonymously? If possible, do not use the switches on the same handler to decide which view triggers the callback?

Solution

Eclipse's Android development tools don't have the functionality you mentioned in the first question - you have to implement the code manually

Get the oncreate button from the view in your activity and attach a listener To answer your second question, the code is:

button1= (Button) findViewById(R.id.button1);
button1.setOnClickListener(new Button1Listener());

Button1listener is a class that handles Click to somebutton - you can ignore the view given to you in onclick

class Button1Listener implements OnClickListener {

    @Override
    public void onClick(View v) {
        // do stuff
    }
}

The button XML is:

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>