Click here to Skip to main content
14,454,989 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Every One

i have a very bad error

i have list view with a custom Adapter

if i put 15 row in list win i make for loop

the loop in visible item on the screen only

if the screen take 10 item it will loop in 10 item only
and can't loop on other 5 item

this image [^]

Screenshot-1581700677 — ImgBB[^]

What I have tried:

this is custom adapter

<pre>package com.bella_system.mostafasalama.bellasystem;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import static com.bella_system.mostafasalama.bellasystem.Constant.Add_Units_Count;
import static com.bella_system.mostafasalama.bellasystem.Constant.ItemID;
import static com.bella_system.mostafasalama.bellasystem.Constant.ItemName;
import static com.bella_system.mostafasalama.bellasystem.Constant.TextLineID;
import static com.bella_system.mostafasalama.bellasystem.Constant.TextLineM;
import static com.bella_system.mostafasalama.bellasystem.Constant.SUintID;
import static com.bella_system.mostafasalama.bellasystem.Constant.TextPrice;
import static com.bella_system.mostafasalama.bellasystem.Constant.TextQty;
import static com.bella_system.mostafasalama.bellasystem.Constant.TextSubQty;
import static com.bella_system.mostafasalama.bellasystem.Constant.Total_COLUMN;
import static com.bella_system.mostafasalama.bellasystem.Constant.UintTwoID;
import static com.bella_system.mostafasalama.bellasystem.Constant.UintTwoPrice;
public class ListViewAdapter extends BaseAdapter{
public ArrayList<HashMap<String, String>> list;
Activity activity;
public ListViewAdapter(Activity activity,ArrayList<HashMap<String, String>> list){
        this.activity = activity;
        this.list = list;

    @Override public int getCount() { return list.size(); }
    @Override public Object getItem(int position) { return list.get(position); }
    @Override public long getItemId(int position) { return 0; }

    private class ViewHolder{
        TextView TextLineID;
        TextView TextItemID;
        TextView textLineM;
        TextView TextItemName;
        TextView TextTextQty;
        TextView TextPrice;
        TextView TextSubQty;
        TextView UintTwoPrice;
        TextView TextItemTotal;
        TextView TextUintID;
        TextView UintTwoID;
        TextView Add_Units_Count;

    public View getView(int position, View convertView, ViewGroup parent) {
     ViewHolder holder;
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView=inflater.inflate(R.layout.datagridviewinv, parent,false);
            holder=new ViewHolder();
            holder.TextLineID = (TextView) convertView.findViewById(;
            holder.TextItemID=(TextView) convertView.findViewById(;
            holder.textLineM=(TextView) convertView.findViewById(;
            holder.TextItemName=(TextView) convertView.findViewById(;
            holder.TextTextQty=(TextView) convertView.findViewById(;
            holder.TextPrice=(TextView) convertView.findViewById(;
            holder.TextSubQty=(TextView) convertView.findViewById(;
            holder.UintTwoPrice=(TextView) convertView.findViewById(;
            holder.TextItemTotal=(TextView) convertView.findViewById(;
            holder.TextUintID=(TextView) convertView.findViewById(;
            holder.UintTwoID=(TextView) convertView.findViewById(;
            holder.Add_Units_Count=(TextView) convertView.findViewById(;
        } else{ holder=(ViewHolder) convertView.getTag(); }

        HashMap<String, String> map = list.get(position);
     if (map != null) {
        return convertView;

and this is my for loop

  for (int i = 0; i < listView.getAdapter().getCount(); i++) {
    if (listView.getChildAt(i) != null) {
    TextView LineID = (TextView) listView.getChildAt(i).findViewById(;
    TextView ItemIDV = (TextView) listView.getChildAt(i).findViewById(;
    TextView LineNumber = (TextView) listView.getChildAt(i).findViewById(;
    TextView ItemName = (TextView) listView.getChildAt(i).findViewById(;
    TextView Qty = (TextView) listView.getChildAt(i).findViewById(;
    TextView SubQty = (TextView) listView.getChildAt(i).findViewById(;
    TextView Price = (TextView) listView.getChildAt(i).findViewById(;
    TextView ItemTotal = (TextView) listView.getChildAt(i).findViewById(;
    TextView SUintID = (TextView) listView.getChildAt(i).findViewById(;
    TextView TUintTwoID = (TextView) listView.getChildAt(i).findViewById(;
    TextView UintTwoPriceV = (TextView) listView.getChildAt(i).findViewById(;
    TextView Add_Units_CountASDV = (TextView) listView.getChildAt(i).findViewById(;


Please Help Me
Updated 14-Feb-20 13:38pm
Kris Lantz 14-Feb-20 13:45pm
Have you:
1) Verified the listView.getAdapter().getCount(); is returning the correct value (of 15)?
2) If 1 is correct, that all listView items have children?
Mostafa Salama S 14-Feb-20 13:56pm
Yes return with 15 row
No itcs have no children it's only row

I need to save the 15 row in database
Kris Lantz 14-Feb-20 15:01pm
for (int i = 0; i < listView.getAdapter().getCount(); i++) {
if (listView.getChildAt(i) != null) {}
The second line is checking if the listview has children (for that iteration.)
My point 2) is asking if you have verified that
if(listView.getChildAt(i) != null) {}
is in fact not null for all 15 iterations of the loop.
Mostafa Salama S 14-Feb-20 16:27pm
if i remove line two he give me null expointer

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

thank you the solution in the line

for (int i1 = 0; i1 < listView.getAdapter().getCount(); i1++) {
HashMap<String, String> itemMap = list.get(i1);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100