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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:25:10+00:00 2026-05-27T01:25:10+00:00

I am trying to create a Custom List View Adapter by extending the ArrayList

  • 0

I am trying to create a Custom List View Adapter by extending the ArrayList

When i do the following i am not able to get the Image from the URL and display it in the List View but it displays the default Image from the XML

Item.java

public class Item {

    String itemTitle = "", itemTimestamp = "", itemDescription = "", itemImage ="";
    public Item(String itemTitle, String itemTimestamp, String itemDescription,
            String itemImage) {
        this.itemTitle = itemTitle;
        this.itemDescription = itemDescription;
        this.itemTimestamp = itemTimestamp;
        this.itemImage = itemImage;
    }

    public String getItemTitle() {
        return itemTitle;
    }

    public void setItemTitle(String itemTitle) {
        this.itemTitle = itemTitle;
    }

    public String getItemTimestamp() {
        return itemTimestamp;
    }

    public void setItemTimestamp(String itemTimestamp) {
        this.itemTimestamp = itemTimestamp;
    }

    public String getItemDescription() {
        return itemDescription;
    }

    public void setItemDescription(String itemDescription) {
        this.itemDescription = itemDescription;
    }

    public String getItemImage() {
        return itemImage;
    }

    public void setItemImage(String itemImage) {
        this.itemImage = itemImage;
    }

}

ListAdapter.java

public class ListAdapter extends ArrayAdapter<Item> {

    public ListAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
        // TODO Auto-generated constructor stub
    }

    private List<Item> items;

    public ListAdapter(Context context, int resource, List<Item> items) {
        super(context, resource, items);
        this.items = items;

    }

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

        if (v == null) {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            v = vi.inflate(R.layout.list_item_default, null);
        }

        Item p = items.get(position);

        if (p != null) {

            TextView list_title = (TextView) v.findViewById(R.id.list_title);
            TextView list_description = (TextView) v
                    .findViewById(R.id.list_description);
            TextView list_timestamp = (TextView) v
                    .findViewById(R.id.list_timestamp);
            ImageView list_image = (ImageView) v.findViewById(R.id.list_image);

            if (list_title != null) {
                list_title.setText(p.getItemTitle());
            }

            if (list_description != null) {
                list_description.setText(p.getItemDescription());
            }

            if (list_timestamp != null) {
                list_timestamp.setText(p.getItemTimestamp());
            }

            if (list_image != null) {
                Uri imageURI = Uri.parse(p.getItemImage());
                list_image.setImageURI(imageURI);
            }
        }

        return v;
    }

}

MessageActivity.java

public class MessagesActivity extends Activity {

    ListView listview;
    static ArrayList<Item> dataArray = new ArrayList<Item>();
    static ArrayList<Item> contentArray = new ArrayList<Item>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_messages);

        setupViews();
        try {
            contentArray = generateArray(createJson());
            Log.d("bMobile", createJson());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Log.d("bMobile", "start ListAdapter");
        listview.setAdapter(new ListAdapter(MessagesActivity.this, R.layout.list_item_default,
                contentArray));
        Log.d("bMobile", "end ListAdapter");
    }

    public void setupViews() {

        listview = (ListView) findViewById(R.id.list_items);

        ((TextView) findViewById(R.id.title_text))
                .setText(R.string.description_messages);
    }

    // It creates a JSON and returns JSON string
    public String createJson() throws JSONException {
        JSONArray itemArray = new JSONArray();

        JSONObject itemObject1 = new JSONObject();
        itemObject1.put("title", "Harsha MV");
        itemObject1.put("timestamp", "2 hours");
        itemObject1.put("description", "Bangalore, India");
        itemObject1.put("display_photo", "http://i.imgur.com/enUZr.jpg");

        JSONObject itemObject2 = new JSONObject();
        itemObject2.put("title", "Avinash G");
        itemObject2.put("timestamp", "4 days");
        itemObject2.put("description", "Mysore, India");
        itemObject2.put("display_photo",
                "http://imgn.dt07.net/1077/1077092_b.jpg");

        JSONObject itemObject3 = new JSONObject();
        itemObject3.put("title", "Jyosna Sahoo");
        itemObject3.put("timestamp", "1  year");
        itemObject3.put("description", "Rourkela, India");
        itemObject3.put("display_photo",
                "http://imgn.dt07.net/1099/1099091_b.jpg");

        itemArray.put(itemObject1);
        itemArray.put(itemObject2);
        itemArray.put(itemObject3);

        return itemArray.toString();
    }

    public ArrayList<Item> generateArray(String JSONdata) throws JSONException {

        JSONArray listData = new JSONArray(JSONdata);
        for (int i = 0; i < listData.length(); i++) {

            JSONObject listObject = listData.getJSONObject(i);
            String item_title = listObject.getString("title");
            String item_timestamp = listObject.getString("timestamp");
            String item_description = listObject.getString("description");
            String item_image = listObject.getString("display_photo");

            Item ObjectItem = new Item(item_title, item_description,
                    item_timestamp, item_image); 
            dataArray.add(ObjectItem);

        }
        return dataArray;
    }

}

activity_messages.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/title_container"
        style="@style/TitleBar" >

        <ImageButton
            style="@style/TitleBarAction"
            android:contentDescription="@string/description_home"
            android:onClick="onHomeClick"
            android:src="@drawable/ic_title_home" />

        <ImageView style="@style/TitleBarSeparator" />

        <TextView
            android:id="@+id/title_text"
            style="@style/TitleBarText" />

        <ImageView style="@style/TitleBarSeparator" />

        <ImageButton
            android:id="@+id/btn_title_refresh"
            style="@style/TitleBarAction"
            android:contentDescription="@string/description_refresh"
            android:onClick="onRefreshClick"
            android:src="@drawable/ic_title_refresh" />

        <ProgressBar
            android:id="@+id/title_refresh_progress"
            style="@style/TitleBarProgressIndicator"
            android:visibility="gone" />
    </LinearLayout>

    <ListView
        android:id="@+id/list_items"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/list_empty_visitors" />

</LinearLayout>

list_item_default.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/list_image"
            android:layout_width="64dip"
            android:layout_height="64dip"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="8dip"
            android:background="@drawable/profile" >
        </ImageView>

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/list_image"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/relativeLayout2"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent" >

                <TextView
                    android:id="@+id/list_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_toLeftOf="@+id/list_timestamp"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:text="Harsha Mallikarjun Vantagudi"
                    android:textSize="@dimen/text_size_medium"
                    android:textStyle="bold" >
                </TextView>

                <TextView
                    android:id="@+id/list_timestamp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:padding="6dip"
                    android:paddingLeft="30dip"
                    android:singleLine="true"
                    android:text="2 hours"
                    android:textSize="@dimen/text_size_xxsmall" >
                </TextView>
            </RelativeLayout>

            <TextView
                android:id="@+id/list_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="Bangalore, India Bangalore, India Bangalore, India Bangalore, India"
                android:textSize="@dimen/text_size_small" >
            </TextView>
        </LinearLayout>
    </RelativeLayout>

</LinearLayout>
  • 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-27T01:25:10+00:00Added an answer on May 27, 2026 at 1:25 am

    generateArray(...) returns null, which you’re setting contentArray to and then passing into your constructor method. You’re populating dataArray then never using it.

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

Sidebar

Related Questions

I am trying to create a custom List Adapter which has an Image for
I am trying to create a custom view for a sharepoint list, similar to
I'm trying to create a custom view (one that is not 100% listview, for
I am trying to create a custom context processor which will render a list
I am trying to create a list view which as TextView that can display
Ok, I am trying to create a custom view called CheckedRelativeLayout . It's purpose
I'm trying to create a custom list which will have checkboxes that allow you
I'm trying to create a listbox in C# to view my contacts list. Can
Hi I've been having some trouble trying to get a list view I created
I'm trying to create a custom UIMenuController and display it in my view. Here's

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.