Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6031211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:08:59+00:00 2026-05-23T05:08:59+00:00

in my app i use image button in list view. i write action for

  • 0

in my app i use image button in list view. i write action for each image button. but i get java.lang.NoSuchMethodException: onClick exception. i do not know the reason for error please help me. how to write action for the image buttons . thanks in advance.

public class InventoryListActivity extends ListActivity {
  private InventoryAdapter adapter;
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.inventory_list);
    adapter = new InventoryAdapter(this);
    setListAdapter(adapter);
 }
}

in InventoryAdapter activity:

public class InventoryAdapter extends BaseAdapter implements Observer,OnClickListener {


public InventoryAdapter(Context ctx) {     
    context = ctx;
    inventory = IAPManager.shared().getInventory();
    inventory.addObserver(this);
    inventory.load();
}

public void update(Observable o, Object arg) {

    switch ( ((Inventory)arg).getStatus() ) {
    case LOADED:
        this.notifyDataSetChanged();
        break;
    default:
        break;
    }
}

@Override
public int getCount() {
    return inventory.size(Inventory.FilterType.ALL);
}

@Override
public Object getItem(int position) {
    return inventory.getProducts(Inventory.FilterType.ALL).get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Product product = (Product) getItem(position);

    View view;

    if(convertView == null) {
        LayoutInflater inflater = (LayoutInflater)
        context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.inventory_list_item, null);
    }

    else {
        view = convertView;
    }

    play = (ImageButton)findViewById(R.id.imageButton2);
    detail = (ImageButton)findViewById(R.id.imageButton3);
    buy = (ImageButton)findViewById(R.id.imageButton2);

    play.setTag(position);
    detail.setTag(position);
    buy.setTag(position);

    titleView = (TextView) view.findViewById(R.id.product_title);
    titleView.setText(product.getTitle());


    iconView = (ImageView) view.findViewById(R.id.product_icon);

    String iconURL = product.getIconURLString();

    if(AsyncImageLoader.contains(iconURL)) {
        iconView.setImageDrawable(AsyncImageLoader.get(iconURL));
    }

    else {
        iconView.setImageDrawable(null);
        new AsyncImageLoader(product.getIconURLString(), new AsyncImageLoader.Delegate(){
            public void imageLoaded(String urlString, Drawable imageDrawable) {
                notifyDataSetChanged();
            }
        });
    }

    descriptionView = (TextView) view.findViewById(R.id.product_description);
    descriptionView.setText(product.getDescription());

    return view;
}

private ImageButton findViewById(int imagebutton2) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onClick(View v) {

    Log.e("onclick","onclick");
    Integer position = (Integer) v.getTag();
    switch(v.getId()){
    case R.id.imageButton1:
       Log.e("Buy","buy position"+position);

    break;
    case R.id.imageButton2:
        Log.e("play","play position"+position);
    break;
    case R.id.imageButton3:
        Log.e("detail","detail  position"+position);
    break;  
    }       
}

}

in xml:

            <ImageButton android:background="@drawable/play_btn"    android:focusable="false" android:onClick="onClick"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/imageButton2" android:layout_weight="0.5" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:09:00+00:00Added an answer on May 23, 2026 at 5:09 am

    I think the problem is, that you’re trying to wire up the onClick listener via xml but implement it in your adapter. I think android simply doesn’t recognize the onClick listener or doesn’t know that is should be used for the ImageButton. Try to implement and add the OnClickListener dynamically in the getView() method.

    UPDATE

    Check the first if statement of the getView() method. There the OnClickListener will be set for the 3 buttons. As your adapter implements the OnClickListener interface you pass the adpater to the method. You also have to remove the android:onClick="onClick" attribute from your ImageButtons in the layout xml file.

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Product product = (Product) getItem(position);
    
            View view;
    
            if(convertView == null) {
                LayoutInflater inflater = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = inflater.inflate(R.layout.inventory_list_item, null);
    
                play = (ImageButton)findViewById(R.id.imageButton2);
                detail = (ImageButton)findViewById(R.id.imageButton3);
                buy = (ImageButton)findViewById(R.id.imageButton2);
    
                // Set the OnClickListener for the 3 image buttons. 
                play.setOnClickListener(this);
                detail.setOnClickListener(this);
                buy.setOnClickListener(this);
    
            }
    
            else {
                view = convertView;
            }
    
            play = (ImageButton)findViewById(R.id.imageButton2);
            detail = (ImageButton)findViewById(R.id.imageButton3);
            buy = (ImageButton)findViewById(R.id.imageButton2);
    
            play.setTag(position);
            detail.setTag(position);
            buy.setTag(position);
    
            titleView = (TextView) view.findViewById(R.id.product_title);
            titleView.setText(product.getTitle());
    
    
            iconView = (ImageView) view.findViewById(R.id.product_icon);
    
            String iconURL = product.getIconURLString();
    
            if(AsyncImageLoader.contains(iconURL)) {
                iconView.setImageDrawable(AsyncImageLoader.get(iconURL));
            }
    
            else {
                iconView.setImageDrawable(null);
                new AsyncImageLoader(product.getIconURLString(), new AsyncImageLoader.Delegate(){
                    public void imageLoaded(String urlString, Drawable imageDrawable) {
                        notifyDataSetChanged();
                    }
                });
            }
    
            descriptionView = (TextView) view.findViewById(R.id.product_description);
            descriptionView.setText(product.getDescription());
    
            return view;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my app i have a list view. Each list consists of a image,
in my app i use list view with setonclickListener . if i try go
in my app i use list view. in the list view i have three
I am trying to use a custom title to include an image button to
I wrote a little Java servlet that would dynamically generate an image button given
in my app i want use the camera for capturing image and send to
We wanted to use a UITabBar in our iPhone app, but with one exception:
I have a navigation based app. Press a button on main view, then I
I have a universal iOS app with a custom view that has three buttons,
I want to create a UIBarButtonItem with a custom image, but I don't want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.