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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:07:28+00:00 2026-06-08T07:07:28+00:00

I have an ArrayAdapter that I use to fill a listview, but I’m unable

  • 0

I have an ArrayAdapter that I use to fill a listview, but I’m unable to create it outside the oncreate event, but at that time I don’t have the data.

public class CusPickup extends Activity {

private OrdersReady orderready_data[];
private ListView lView; 

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

Here I will get a null point exception.

    OrderReadyAdapter adapter = new OrderReadyAdapter(this,R.layout.listview_item_row, orderready_data);
    lView = (ListView)findViewById(R.id.listView1);
    View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
    lView.addHeaderView(header);
    lView.setAdapter(adapter);

getData();
}
}

Here I get the data from HTTP get.

private final Handler handler = new Handler() {

        @Override
        public void handleMessage(final Message msg) {
            progressDialog.dismiss();
            String bundleResult = msg.getData().getString("RESPONSE");
                int TotalRecords = myResult.d.results.size();
                for (int i = x; i < TotalRecords; i++ ) {
                    orderready_data[i] = new OrdersReady(myResult.d.results.get(i).myStr, myDate ,invResult.d.results.get(i).numberStr, invResult.d.results.get(i).qtyInt, myAmount)
                }  
           }
}

If I place the OrderReadyAdapter her I get a code error with a fix “change OrderReadyAdapter(Context, Int, OrdersReady[]) to OrderReadyAdapter(Handle, Int, OrdersReady[]) if I change it I will get more errors.

Also I’m not sure if my declaration of the private OrdersReady orderready_data[] is correct, because if I declare it in code I would declare it like this: OrdersReady orderready_data[] = new OrdersReady[TotalRecords];

Thanks for any help.


New Adapter

public class OrderReadyAdapter extends ArrayAdapter<OrdersReady>{

Context context; 
int layoutResourceId;    
ArrayList<OrdersReady> data = null;

public OrderReadyAdapter(Context context, int layoutResourceId, ArrayList<OrdersReady> orderReadyArray) {
    super(context, layoutResourceId, orderReadyArray);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = orderReadyArray;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    OrderHolder holder = null;

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

        holder = new OrderHolder();
        holder.mytxt1 = (TextView)row.findViewById(R.id.mytxt1);
        holder.mytxt2 = (TextView)row.findViewById(R.id.mytxt2);
        holder.mytxt3 = (TextView)row.findViewById(R.id.mytxt3);
        holder.mytxt4 = (TextView)row.findViewById(R.id.mytxt4);
        holder.mytxt5 = (TextView)row.findViewById(R.id.mytxt5);

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

    OrdersReady orderready = data.get(position);
    holder.mytxt1.setText(orderready.place);
    holder.mytxt2.setText(orderready.Date);
    holder.mytxt3.setText(orderready.invoice);
    holder.mytxt4.setText(String.valueOf(orderready.Qty));
    holder.mytxt5.setText(String.valueOf(orderready.Amount));

    return row;
}

static class OrderHolder
{
    TextView mytxt1;
    TextView mytxt2;
    TextView mytxt3;
    TextView mytxt4;
    TextView mytxt5;
}

}

  • 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-08T07:07:30+00:00Added an answer on June 8, 2026 at 7:07 am

    I suggest you change the OrdersReady[] into ArrayList. Initialize it in your onCreate method. Also make the orderReady adapter into a class field.

    orderReadyArray = new ArrayList<OrderReady>();
    ordersReadyAdapter = new OrderReadyAdapter(this,R.layout.listview_item_row, orderReadyArray);
    lView = (ListView)findViewById(R.id.listView1);
    View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
    lView.addHeaderView(header);
    lView.setAdapter(ordersReadyAdapter);
    

    This should initialize an empty listview as you don’t have the data yet.

    When you receive OrdersReady data from the server, update orderReadyArray as such:

    orderReadyArray.clear(); // remove old data
    for (int i = x; i < TotalRecords; i++ ) {
       orderReadyArray.add(data); // add new data one by one
    }
    ordersReadyAdapter.notifyDataSetChanged(); // this forces the listview to repaint
    

    Alternatively:

    You can create a new adapter and assign it to the listview once you receive the data:

    List<OrderReady> orderReadyArray = new ArrayList<OrderReady>(); // create a new array to hold data
    for (int i = x; i < TotalRecords; i++ ) {
       orderReadyArray.add(data); // add new data one by one
    }
    OrderReadyAdapter ordersReadyAdapter = new OrderReadyAdapter(this,R.layout.listview_item_row, orderReadyArray);
    lView.setAdapter(ordersReadyAdapter);
    

    This should update your list. If you still do not see the items, the problem is in the adapter, perhaps you are inflating the row incorrectly in getView() method.

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

Sidebar

Related Questions

I have a ListView that I want to use with an ArrayAdapter to add
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a ListView that has a custom ArrayAdapter with a custom XML row.
I have made a ListView with an ArrayAdapter. It works. But I had to
I have a custom ArrayAdapter I use to manage my ListView: public class FilesAdapter
I have created a custom ArrayAdapter that fills a ListView . The data in
I have an ArrayAdapter powering a ListView . I would like to change the
I have used ListView and bounded my custom ArrayAdapter to it. Have setOnItemClickListener(...) bound
Doing some R&D for my company. We are trying to have a listView that
I have a ListView that has some minor visual preferences that are set in

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.