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

  • Home
  • SEARCH
  • 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 7854535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:05:31+00:00 2026-06-02T20:05:31+00:00

I have a listview with a custom adapter, the adapter contains two TextViews and

  • 0

I have a listview with a custom adapter, the adapter contains two TextViews and one ImageButton. The list contains objects of my class Firm. When a user presses the ImageButton I want to get some information from the Firm object, by using a get()-method.

Some Codesnippets underneath

My CustomAdapter

import java.util.Vector;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class CustomAdapter extends ArrayAdapter<Firm>
{
 Context context;
 int layoutResourceId;   
 static String datesort; 
 ImageButton call;
 Firm mrb;

 Firm currentMRB;
 Vector<Firm> data;
/** Called when the activity is first created. */
// TODO Auto-generated constructor stub
public CustomAdapter(Context context, int layoutResourceId, Vector<Firm> data) 
{
    super(context,layoutResourceId,data);
    this.layoutResourceId = layoutResourceId;
    this.context=context;
    this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    View row = convertView;
    MyStringReaderHolder holder;

    if(row==null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent,false);

        holder= new MyStringReaderHolder();

        holder.gtumcaTvFirstName =(TextView)row.findViewById(R.id.gtumcaTvFirstName);
        holder.gtumcaTvLastName =(TextView)row.findViewById(R.id.gtumcaTvLastName);
        call = (ImageButton)row.findViewById(R.id.imageButton1);

        row.setTag(holder);
    }
    else
    {
        holder=(MyStringReaderHolder) row.getTag();
    }

    mrb =data.elementAt(position);
    System.out.println("Position="+position);

    holder.gtumcaTvFirstName.setText(mrb.getCompanyName());
    int price = (int)mrb.getPrice();
    String priceString = Integer.toString(price);
    holder.gtumcaTvLastName.setText(priceString);


    call.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {


            Toast.makeText(context, mrb.getNumber(), Toast.LENGTH_LONG).show(); 

        }
    });

    return row;

}

Look at the getView() function, this contains a OnClickListener() method that I want to run when the user presses one of the items in the ListView, the function should raise a Toast with the object’s get() method

But it doesn’t work. Does anybody know how I can complete this task? Thanks in advance.

UPDATE

I’ve found whats wrong, I forgot that the Button was a ImageButton rather than a regular Button. But how can I get the objects number? My Toast just generates random numbers from the getNumber() method based on all the objects, more specified I want the number of the object in e.g position 3 in my list.

  • 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-06-02T20:05:33+00:00Added an answer on June 2, 2026 at 8:05 pm

    I solved my problem by doing it this way:

     static class MyStringReaderHolder
     {
        TextView gtumcaTvFirstName,gtumcaTvLastName,gtumcaTvBirthDate;
        ImageView gtumcaIvIcon;
        ImageButton call;
     }
    

    And create a new instance of the static class

            holder= new MyStringReaderHolder();
            holder.call = (ImageButton)row.findViewById(R.id.imageButton1);
            holder.call.setFocusable(false);
    

    Finally I added an OnClickListener to the ImageButton

    holder.call.setOnClickListener(new OnClickListener() {
    
            public void onClick(View arg0) {
    
    
            Toast.makeText(context,  "" +  data.elementAt(position).getCompanyName(), Toast.LENGTH_SHORT).show(); 
    
            }
        });
    

    Thanks guys! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have created custom listview by using the Base adapter. List view contains Text
I currently have a custom listview where each item on the list contains two
I have a listview connected to a custom array adapter. This list shows information
I have a ListView with a custom view rendered by an adapter. It contains
I have created a custom listview using adapter. Each row of the list view
I have a listview with custom array adapter, the view allows the user to
I have a ListView that contains a list of TextViews, and in my onItemClick()
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have a ListView with a custom Adapter that creates rows containing TextViews that
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately, the class

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.