开发者

Setting ClickListener from the Layout

Having problems to set ClickListener from Layout

Inside my layout:

<ImageButton 
    android:id="@+id/VimeoButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:src="@drawable/vimeo_icon"
    android:onClick="OpenVimeo"
>

And in the main class (an activity):

public void OpenVimeo(View v)
    {

        Intent myIntent;
        Log.i(tag,"Inside");
        myIntent=new Intent (AndroidRSS.this,Video.class);
        startActivity(myIntent);
    }

But seems not to ha开发者_运维问答ndle click events.


When we give onClick inside layout, no need to give switch case inside your

public void OpenVimeo(View v) 

OpenVimeo method is given inside onClick for the ImageButton. So only on clicking the ImageButton the code inside the method will work.

And regarding the solution...

Instead of this ImageButton if you give it as a normal button it will work. Instead of

android:src=""

give android:background="" for button.

If you still want to use ImageButton, add android:clickable="true" to your ImageButton tag and see. I think it may work. Please give a try and just reply if it worked.


your code is right but may be u forgot add activity in android.manifeast

so add activity to android.manifeast


I think you forgot about switch... public void OpenVimeo(View v) { //first switch(v) { case VimeoButton:

    Intent myIntent;
    Log.i(tag,"Inside");
    myIntent=new Intent (AndroidRSS.this,Video.class);
    startActivity(myIntent);
  }

//another casesss.. }

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜