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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:07:17+00:00 2026-05-27T21:07:17+00:00

list_item.java public class List_Items extends ListActivity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_item); ListView

  • 0

list_item.java

  public class List_Items extends ListActivity{

 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
       setContentView(R.layout.list_item);


       ListView lv = (ListView) this.findViewById(android.R.id.list);

       lv.setAdapter((ListAdapter) new ImageAndTextListAdapter(this, xxx));


      Button btn=(Button) findViewById(R.id.button_sync);
      btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
                    }
                    // code here
                }
              }

ImageAndTextListAdapter.java

    public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText> {

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

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

    //new method
    this.listView = listView;
    asyncImageLoader = new AsyncImageLoader();
}

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

}

}

ImageAndText.java

   public class ImageAndText {
    private String imageUrl;
   private String text;

public ImageAndText(String imageUrl, String text) {
    this.imageUrl = imageUrl;
    this.text = text;
}
public String getImageUrl() {
    return imageUrl;
}
public String getText() {
    return text;
}

}

AsyncImageLoader.java

  public class AsyncImageLoader {
  private HashMap<String, SoftReference<Drawable>> imageCache;
  HashMap<String, SoftReference<Drawable>> drawableMap = new HashMap<String,          SoftReference<Drawable>>();


public AsyncImageLoader() {
    //HashMap<String, SoftReference<Drawable>> drawableMap = new HashMap<String, SoftReference<Drawable>>();
}

public Drawable loadDrawable(final String imageUrl, final ImageCallback imageCallback) {

    if (drawableMap.containsKey(imageUrl)) {
        SoftReference<Drawable> softReference = imageCache.get(imageUrl);
        Drawable drawable = softReference.get();
        if (drawable != null) {
            return drawable;
        }
    }
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            imageCallback.imageLoaded((Drawable) message.obj, imageUrl);
        }
    };

    //this is the new thread that download the image from url
    new Thread() {
        @Override
        public void run() {
            Drawable drawable = loadImageFromUrl(imageUrl);
            imageCache.put(imageUrl, new SoftReference<Drawable>(drawable));
            Message message = handler.obtainMessage(0, drawable);
            handler.sendMessage(message);
        }
    }.start();
    return null;
}

public static Drawable loadImageFromUrl(String url) {
      InputStream inputStream;
      try {
          inputStream = new URL(url).openStream();
      } catch (IOException e) {
          throw new RuntimeException(e);
      }
      return Drawable.createFromStream(inputStream, "src");
}

public interface ImageCallback {
    public void imageLoaded(Drawable imageDrawable, String imageUrl);
}

}

In this example, the listview of the list_item.java is initially empty, and it will call the ImageAndTextListAdapter which will call the web url to supply the listview row of data of image and Text dynamically.

The question I have is how to call the Adapter, lv.setAdapter((ListAdapter) new ImageAndTextListAdapter(this, xxx)); What should be xxx be? can I just do a xxx=List imageAndTexts which list of the ImageAndText class but isn’t that duplicate what’s inside the ImaheAndTextListAdapter constructor?

Secondly, what should I supply inside the click routine, public void onClick(View v) {
}
// code here
}
} inside the list_item.
The goal of mine is hit the button and that will initiate the action of adpater supplying all the necessary data.

  • 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-27T21:07:18+00:00Added an answer on May 27, 2026 at 9:07 pm

    From the ImageAndTextListAdapter adapter the xxx should be a List.

    Your adapter takes two parameters of a Activity, and List.

    So you should create a List, and create objects of ImageAndText class to add to the list like this..

    ImageAndText image = new ImageAndText("url","Test");
     List<ImageAndText>text;
     text.add(image); //Add the Object of ImageAndText
     ListView lv = (ListView) findViewById(android.R.id.list);
    
     //Here i supply the adapter with the text list created.
     lv.setAdapter((ListAdapter)new ImageAndTextListAdapter(Main.this, text));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an ArrayList in my Application class : package a.b.layout; import java.util.ArrayList;
I have a class which extends ListActivity within I have all methods for managing
Here is my .java file: package com.shoppinglist; import java.util.ArrayList; import android.app.Dialog; import android.app.ListActivity; import
package sg.edu.rp.c345.p04; import java.util.ArrayList; import java.util.Collections; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; import android.os.Bundle;
I have a mainActivity which is Customer.java with listview of 5 diff. activities. I
I have a problem understanding why is my ListActivity and its corresponding listView empty
I am having a list like <li style=display: list-item; id=listChoices> <label class=topspace>Enter the Choices</label>
I want a simple TextView to behave the way simple_list_item_1 in a ListView does.
Just a disclaimer, I'm very new to both android and Java. The end product
The following is my code for SettingsActivity.java. The main activity starts this activity by

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.