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 7057513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:59:42+00:00 2026-05-28T03:59:42+00:00

public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText> { // new method private ListView listView; private AsyncImageLoader

  • 0
public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText> {

//   new method
    private ListView listView;
    private AsyncImageLoader asyncImageLoader;
     private ImageAndText imageAndText;

//constructor
public ImageAndTextListAdapter(Activity activity, List<ImageAndText> imageAndTexts) {
    super(activity, 0, imageAndTexts);


    asyncImageLoader = new AsyncImageLoader();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Activity activity = (Activity) getContext();


    ////////////////////////////////////////////////////////////////////////////////////////////////
    // Load the image and set it on the ImageView


    //new method
    // Inflate the views from XML
    View rowView = convertView;
    ViewCache viewCache;

    if (rowView == null) {
        LayoutInflater inflater = activity.getLayoutInflater();
        rowView = inflater.inflate(R.layout.image_and_text_row, null);
        viewCache = new ViewCache(rowView);
        rowView.setTag(viewCache);
    } else {
        viewCache = (ViewCache) rowView.getTag();
    }
    imageAndText = getItem(position);

    Button btn2=(Button) findViewById(R.id.button1);

      btn2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

                     //...........
               }
      });

This adapter is for the ListView, and it takes the image_and_text_row.xml which represent the row data of the listview. The program crashed when I set a click listener to the btn2. If the listener is deleted then the program runs fine.

the question is why the adapter cannot have a button click listener inside the code?

  • 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-28T03:59:43+00:00Added an answer on May 28, 2026 at 3:59 am

    Just a shot in the dark: but your line Button btn2=(Button) findViewById(R.id.button1); refers to the ListActivity or ListView that the adapter is in. Therefore, R.id.button1 does not exist…

    Have you tried: Button btn2=((Button)rowView.findViewById(R.id.button1)); This may be your issue (without being able to see your logcat, that is). findViewById() finds children. The original statement would look for the child of the Activity or View. This new statement would find the child of the rowView.

    Of course, this is an assumption, as since you have not described the application or problem completely, I must assume according to the information that we do have that there is a button for every row.

    Hope this helps,

    FuzzicalLogic

    P.S. Hope you caught the hint that you will get shoddy answers like this one if there is a lack of pertinent information. A good guide is: 1) What is happening? 2) What do you expect to happen? 3) What do your debugging resources indicate? 4) What supplemental research or concepts do we need to know? These lead to longer questions, but they are certainly more effective and so are the answers that result from them.

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

Sidebar

Related Questions

public class WordDisplay extends Activity { private int level; private int group; private int
public class List_Items extends ListActivity{ private ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); public
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
public class A{ List m; public A(int a, int b) {m=new List(); ...} }
list_item.java public class List_Items extends ListActivity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_item); ListView
public class abc<X extends Z> implements Iterable<X> { protected ArrayList<X> list; public Iterator<X> iterator()
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class Offer_Popup extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.offer_popup); //newly

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.