0
package com.in2em.hotel;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log; 
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressLint("ParserError")

Activity to display two arraylist in listview

  public class OrderActivity extends ListActivity {
    ArrayList<String> data,rate;
    OrderAdapter orderAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order);
        Bundle extras = getIntent().getExtras(); 
        data = extras.getStringArrayList("list");
        rate = extras.getStringArrayList("rate");
        for(String str : data)  {
            Log.d("data", str);

        }
        for(String str1 : rate) {
            Log.d("data", str1);

        }

data and rate are two arraylist

        String[] captionArray = (String[]) data.toArray(
                new String[data.size()]);
        String[] rateArray = (String[]) rate.toArray(
                new String[rate.size()]);
        R.layout.order_list,R.id.itemname, captionArray));

How to set the two array list in listview ? I can set only one arraylist ?

     orderAdapter = new OrderAdapter(
                OrderActivity.this, R.layout.order_list,
                captionArray);

setting the list adapter

        setListAdapter(orderAdapter);

        return ;
    }

Custum listAdapter

         private class OrderAdapter extends BaseAdapter {
        String[] items;

        public OrderAdapter(Context context, int textViewResourceId,
                String[] items) {
            this.items = items;
        } 

Returning the views

        public View getView(final int POSITION, View convertView,
                ViewGroup parent) {

            TextView tvNumber,tvName,tvRate;
            EditText etQty,etRemarks;

            View view = convertView;

Inflate

            if (view == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.order_list, null);

            } 
                tvName = (TextView) findViewById(R.id.itemname);
            tvRate = (TextView) findViewById(R.id.itemrate);

            tvName.setText(data.get(POSITION));
            tvRate.setText(rate.get(POSITION));


            return view; 
        }


        public int getCount() {
            // TODO Auto-generated method stub
            return items.length;
        }


        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }


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

}
2
  • Use a third one created from these two ArrayList. Commented Nov 18, 2012 at 6:52
  • Add contents of the two arraylists to a third one and use the third one in your program. Commented Nov 18, 2012 at 6:59

2 Answers 2

1

Change your constructor to accept two ArrayLists and store them within the Adapter:

private class OrderAdapter extends BaseAdapter {
    ArrayList<String> data;
    ArrayList<String> rate;

    public OrderAdapter(Context context, ArrayList<String> data, ArrayList<String> rate) {
        this.data = data;
        this.rate = rate;
    } 

    // Use the same getView(), for now

    public int getCount() {
        return data.size(); // rate must be the same size as data!
    }

    public String getItem(int position) {
        return data.get(position);
    }

And use it like this:

 orderAdapter = new OrderAdapter(this, data, rate);

Also you should watch this Android lecture on adapters and ListViews to speed up getView().

Sign up to request clarification or add additional context in comments.

Comments

0
List<String> firstList = new ArrayList<String>();
List<String> secondList = new ArrayList<String>();
List<String> thirdList;
firstList.add("...");
secondList.add("...");

thirdList = new ArrayList<String>(firstList);
thirdList.addAll(secondList);

Apply thirdList to your Adapter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.