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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:46:27+00:00 2026-06-03T23:46:27+00:00

I want to bind some data gotten from a web service to a custom

  • 0

I want to bind some data gotten from a web service to a custom listview…
My listview has one imageview and three textviews…

Most of the tutorials I’ve read on it suggest that an adapter class should be made, so I’ve currently written an adapter like below:

public class InboxAdapter extends BaseAdapter {

    private Context context;

    private List<MailInbox> mails;

    public InboxAdapter(Context context, List<MailInbox> mails)
    {
        this.context = context;
        this.mails = mails;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mails.size();
    }

    @Override
    public Object getItem(int item) {
        // TODO Auto-generated method stub
        return mails.get(item);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        MailInbox entry = mails.get(position);

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

        ImageView mailImg = (ImageView)convertView.findViewById(R.list.mail_thumb);
        //Set the appropriate image - either unread or read

        TextView author = (TextView)convertView.findViewById(R.list.mail_text);
        TextView body = (TextView)convertView.findViewById(R.list.mail_detail);
        TextView date = (TextView)convertView.findViewById(R.list.mail_date);

        author.setText(entry.AuthorName);
        body.setText(entry.MessageBody);
        date.setText(entry.CreatedAt);

        return convertView;
    }
}

So this is this part where I’m stuck.. I now have an adapter, but I’m not completely sure how to use it…

In the activity that has the listview:

Update:

Okay, so I’m trying to fill the adapter like this:

private void setUpList()
{
    list = (ListView)findViewById(R.id.mail_list);      

    final List<MailInbox> mails = new ArrayList<MailInbox>();

    for(int i = 0; i < mMessages.myMail.size(); i++)
    {
        MailInbox inbox = new MailInbox();

        inbox.setProperty(0, mMessages.myMail.get(i).CreatedAt);
        inbox.setProperty(1, mMessages.myMail.get(i).MessageBody);
        inbox.setProperty(3, mMessages.myMail.get(i).AuthorName);
        inbox.setProperty(4, mMessages.myMail.get(i).IsRead);//used to determine the image that will be in the imageview

        mails.add(inbox);
    }

    // Just to check if it's added properly - it outputs 5
    int length = mails.size();
    System.out.println("Size: " + length);

    InboxAdapter adapter = new InboxAdapter(this, mails);

    list.setAdapter(adapter);
}

But on list.setAdapter(adapter), I get a Nullpointer exception

Entire error:

05-14 17:43:17.855: E/AndroidRuntime(976): FATAL EXCEPTION: main
05-14 17:43:17.855: E/AndroidRuntime(976): java.lang.NullPointerException
05-14 17:43:17.855: E/AndroidRuntime(976):  at com.cim.daycare.InboxActivity.setUpList(InboxActivity.java:67)
05-14 17:43:17.855: E/AndroidRuntime(976):  at com.cim.daycare.InboxActivity.access$2(InboxActivity.java:43)
05-14 17:43:17.855: E/AndroidRuntime(976):  at com.cim.daycare.InboxActivity$GetMails.onPostExecute(InboxActivity.java:96)
05-14 17:43:17.855: E/AndroidRuntime(976):  at com.cim.daycare.InboxActivity$GetMails.onPostExecute(InboxActivity.java:1)
05-14 17:43:17.855: E/AndroidRuntime(976):  at android.os.AsyncTask.finish(AsyncTask.java:417)
05-14 17:43:17.855: E/AndroidRuntime(976):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
05-14 17:43:17.855: E/AndroidRuntime(976):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
05-14 17:43:17.855: E/AndroidRuntime(976):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 17:43:17.855: E/AndroidRuntime(976):  at android.os.Looper.loop(Looper.java:123)
05-14 17:43:17.855: E/AndroidRuntime(976):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-14 17:43:17.855: E/AndroidRuntime(976):  at java.lang.reflect.Method.invokeNative(Native Method)
05-14 17:43:17.855: E/AndroidRuntime(976):  at java.lang.reflect.Method.invoke(Method.java:507)
05-14 17:43:17.855: E/AndroidRuntime(976):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-14 17:43:17.855: E/AndroidRuntime(976):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-14 17:43:17.855: E/AndroidRuntime(976):  at dalvik.system.NativeStart.main(Native Method)

From doing a bit of Google’ing, it sounds like the problem might lie with the xml-files…
I have two xml’s, one called mail_list and one called mail_list_row…

list:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mail_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="2"
    android:drawSelectorOnTop="false" >    
</ListView>

row:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="48dip"
    android:background="@drawable/listselector"
    >
    <ImageView
        android:id="@+list/mail_thumb"
        android:layout_width="30dip"
        android:layout_height="30dip"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:contentDescription="@string/imgdesc"
        />
    <TextView
        android:id="@+list/mail_text"
        android:layout_toRightOf="@+list/mail_thumb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14dip"
        android:layout_marginLeft="8dip"
        android:layout_centerVertical="false"
        android:singleLine="true"
        android:ellipsize="end"
        android:textStyle="bold"
        android:textColor="@android:color/white"
        />
    <TextView 
        android:id="@+list/mail_detail"
        android:layout_toRightOf="@+list/mail_thumb"
        android:layout_below="@+list/mail_text"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:textSize="12dip"
        android:layout_marginLeft="8dip"
        android:layout_centerVertical="false"
        android:singleLine="true"
        android:ellipsize="end"
        android:textColor="@color/grey"     
        />
    <TextView 
        android:id="@+list/mail_date"
        android:layout_toRightOf="@+list/mail_detail"
        android:layout_below="@+list/mail_text"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:textSize="12dip"
        android:singleLine="true"
        android:ellipsize="end"
        android:textColor="@color/grey"
        android:layout_alignParentRight="true"      
        />
</RelativeLayout>
  • 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-03T23:46:29+00:00Added an answer on June 3, 2026 at 11:46 pm

    try something like

    private void setUpList()
    {
        list = (ListView)findViewById(R.id.mail_list);
         InboxAdapter adapter=new InboxAdapter(this,YourArrayList);
        list.setAdapter(adapter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to bind one data to several controls. Is there some logical control
I'm trying to bind some data to a WPF listview. One of the properties
i want to bind some tabular data in wpf i just want to know
I want to bind some extra data with a view. I am using tag
I use ComboBox.ItemsSource=[some data collection] to bind data to the control. I want to
If I want to bind a collection to a some form of listing control
Say I have some foo :: Maybe Int and I want to bind it
I want to bind my ListView control to a generic list of objects? I
I want to bind one property to multiple sources. My reason for this are
I am using Flot to chart some data that I pull back from the

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.