android - Not sure why getting Duplicate method onClick(View) -


i've got 1 activity here trying do. when app starts image displayed. when image clicked next image displayed. i've got setup main.xml , imageview. app builds , runs , displays first image no problem. trying setup onclick image next image displayed. i've added android:onclick="onclick" image vew in main.xml. using (this) setonclicklistner , implemented view.onclicklistener class switch case setup duplicate method onclick(view v) , i'm not sure why.

also trying figure out findviewbyid think way have image1 displayed.

getting error on line public void onclick(view v) duplicate method.

here code have. assistance on this.

main.xml linear layout not sure matters.

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">  <imageview     android:id="@+id/imageview1"     android:src="@drawable/bear"             android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:onclick="onclick"     android:contentdescription="@string/desc"/>  <imageview     android:id="@+id/imageview2"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:src="@drawable/bear_n"     android:onclick="onclick"     android:contentdescription="@string/desc" /> 

this .java file.

import android.app.activity; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.imageview;   public class vtfcactivity extends activity implements view.onclicklistener{  imageview image; @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      image = (imageview) findviewbyid(r.id.imageview1);     imageview image1 = (imageview) findviewbyid(r.id.imageview1);     imageview image2 = (imageview) findviewbyid(r.id.imageview2);      image1.setonclicklistener(this);     image2.setonclicklistener(this);  } public void onclick(view v) {     switch (v.getid()){      case r.id.imageview1:         image.setimageresource(r.drawable.bear);         break;     case r.id.imageview2:         image.setimageresource(r.drawable.bear_n);         break;               } } 

now trying setup onclick image next image displayed. i've added android:onclick="onclick" image vew in main.xml.

if have added android:onclick="onclick" both image views in main.xml should remove image1.setonclicklistener(this); , image2.setonclicklistener(this); code since have specified in main xml.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -