killer
killer

Reputation: 602

Listview displays only one row from the list

I am new to android listviews and I am trying to populate a listview in android by a list of items coming from a webservice. I know that the list contains more than one record coming from the webservice but my custom listview displays only the first record from the list. I checked the size of the list and there is always more than one records but the listview is showing only one of them. My custom adapter is like following:

public class ListAdapter extends BaseAdapter {
    Context ctx;
    LayoutInflater lInflater;
    ArrayList<LItem> lstItems;

    ListAdapter(Context context, ArrayList<LItem> objects) {
        ctx = context;
        lstItems = objects;
        lInflater = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return lstItems.size();
    }

    @Override
    public Object getItem(int position) {
        return lstItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = lInflater.inflate(R.layout.list_style_task
                    , parent, false);
        }

        LItem p = getProduct(position);

        ((TextView) view.findViewById(R.id.tvMaterial )).setText(p.getMName() );
        ((TextView) view.findViewById(R.id.tvTask )).setText(p.getTName() );
        ((TextView) view.findViewById(R.id.tvBQuantity )).setText(p.getBQ() );

    //  CheckBox cbBuy = (CheckBox) view.findViewById(R.id.checkbox);
        //cbBuy.setOnCheckedChangeListener(myCheckChangList);
    //  cbBuy.setTag(position);
    //  cbBuy.setChecked(p.selected);
        return view;
    }

    LItem getProduct(int position)
    {
        return ((LItem) getItem(position));
    }

    ArrayList<LItem> getBox() {
        ArrayList<LItem> box = new ArrayList<LItem>();
        for (LItem p : lstItems) {
        //  if (p.selected)
            //  box.add(p);
        }
        return box;
    }

    OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            //getProduct((Integer) buttonView.getTag())= isChecked;
        }
    };
}

I am binding the listview as:

 protected void onPostExecute(List<LItem> li ) {
            super.onPostExecute(lstItm);
           if(lstItm.size()>0) {

                 Adp=new ListAdapter(myactivity,lstItm);

               lvTasks.setAdapter(Adp);

               Log.d("Size---------",Integer.toString(lstItm.size()) );//here it writes more than one as size of the list.

    }
}

My xml file for displaying lists is like this:

<?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"


    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"

       >
        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:focusable="false"
            android:textColor="#FFF"
            android:button="@drawable/custom_checkbox_design"

            android:focusableInTouchMode="false"
            android:text="" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Task:"
            android:id="@+id/textView2"
            android:layout_weight="1"
            android:textColor="#FFF"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="task"
            android:id="@+id/tvTask"
            android:layout_weight="1"
            android:textColor="#FFF"
            />


        </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="45dp"
        android:layout_marginRight="20dp"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Material:"
            android:id="@+id/textView1"
            android:layout_weight="1"
            android:textColor="#FFF"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="material"
            android:id="@+id/tvMaterial"
            android:layout_weight="1"
            android:textColor="#FFF"
            />


    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="45dp"
        android:layout_marginRight="20dp"  >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Balanced Quantity:"
            android:id="@+id/textView14"
            android:layout_weight="1"
            android:textColor="#FFF"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="bquantity"
            android:id="@+id/tvBQuantity"
            android:layout_weight="1"
            android:textColor="#FFF"
            />


    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="45dp"
        android:layout_marginRight="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Adjust Balanced Quantity:"
            android:id="@+id/textView25"
            android:layout_weight="1"
            android:textColor="#FFF"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:id="@+id/tvAQuantity"
            android:layout_weight="1"
            android:textColor="#FFF"
            />

        </LinearLayout>


</LinearLayout>

My xml for listview is like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="kanix.highrise.com.highrise.generate_material_requisition">

    <!-- TODO: Update blank fragment layout -->
    <ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/lstTaskQuantity"
        android:layout_weight="1" >


        </ListView>



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp">
            <TextView
                android:id="@+id/txtLddsdfabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="16dp"
                android:text="Req. From :"
                android:layout_weight="1"
                android:textColor="#fff" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="date"

                android:id="@+id/etDate"
                android:layout_weight=".5"

                android:hint="DD/MM/YYYY"/>

            <ImageButton
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:id="@+id/btnimgcal"


                android:src="@drawable/calender"
                />


        </LinearLayout>



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp">
            <TextView
                android:id="@+id/txtLddsdfadsbel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="16dp"
                android:text="For Days :"
                android:layout_weight="1"
                android:textColor="#fff" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="0"

                android:id="@+id/editText"
                android:layout_weight="1.69" />


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp">
            <TextView
                android:id="@+id/txtLddsddfgfadsbel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:textSize="16dp"
                android:text="Quantity :"
                android:layout_weight="1"
                android:textColor="#fff" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="0"

                android:id="@+id/etQuantity"
                android:layout_weight="1.60" />


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_gravity="center"
            android:orientation="vertical"
            >







            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#0080FF"
                android:background="#fff"
                android:text="Generate Requisition"
                android:id="@+id/btnSave" />





        </LinearLayout>




</LinearLayout>



    </ScrollView>
</LinearLayout>

Upvotes: 1

Views: 1039

Answers (1)

killer
killer

Reputation: 602

Issue was with the scrollview which was createing the issue. I just removed

  <ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >


</ScrollView>

and it worked for me :)

Upvotes: 1

Related Questions