Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
https://ibb.co/Zgnx67T [^]

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.app.Activity;
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){
        super();
        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;
    }

    @Override
    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(R.id.TextLineID);
            holder.TextItemID=(TextView) convertView.findViewById(R.id.TextItemID);
            holder.textLineM=(TextView) convertView.findViewById(R.id.TextLineM);
            holder.TextItemName=(TextView) convertView.findViewById(R.id.ItemName);
            holder.TextTextQty=(TextView) convertView.findViewById(R.id.TextQty);
            holder.TextPrice=(TextView) convertView.findViewById(R.id.TextPrice);
            holder.TextSubQty=(TextView) convertView.findViewById(R.id.TextSubQty);
            holder.UintTwoPrice=(TextView) convertView.findViewById(R.id.UintTwoPrice);
            holder.TextItemTotal=(TextView) convertView.findViewById(R.id.TextItemTotal);
            holder.TextUintID=(TextView) convertView.findViewById(R.id.TextUintID);
            holder.UintTwoID=(TextView) convertView.findViewById(R.id.UintTwoID);
            holder.Add_Units_Count=(TextView) convertView.findViewById(R.id.Add_Units_Count);
            convertView.setTag(holder);
        } else{ holder=(ViewHolder) convertView.getTag(); }

        HashMap<String, String> map = list.get(position);
     if (map != null) {
      holder.TextLineID.setText(map.get(TextLineID));
      holder.TextItemID.setText(map.get(ItemID));
      holder.textLineM.setText(map.get(TextLineM));
      holder.TextItemName.setText(map.get(ItemName));
      holder.TextTextQty.setText(map.get(TextQty));
      holder.TextPrice.setText(map.get(TextPrice));
      holder.TextSubQty.setText(map.get(TextSubQty));
      holder.UintTwoPrice.setText(map.get(UintTwoPrice));
      holder.TextItemTotal.setText(map.get(Total_COLUMN));
      holder.TextUintID.setText(map.get(SUintID));
      holder.UintTwoID.setText(map.get(UintTwoID));
      holder.Add_Units_Count.setText(map.get(Add_Units_Count));
     }
        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(R.id.TextLineID);
    TextView ItemIDV = (TextView) listView.getChildAt(i).findViewById(R.id.TextItemID);
    TextView LineNumber = (TextView) listView.getChildAt(i).findViewById(R.id.TextLineM);
    TextView ItemName = (TextView) listView.getChildAt(i).findViewById(R.id.ItemName);
    TextView Qty = (TextView) listView.getChildAt(i).findViewById(R.id.TextQty);
    TextView SubQty = (TextView) listView.getChildAt(i).findViewById(R.id.TextSubQty);
    TextView Price = (TextView) listView.getChildAt(i).findViewById(R.id.TextPrice);
    TextView ItemTotal = (TextView) listView.getChildAt(i).findViewById(R.id.TextItemTotal);
    TextView SUintID = (TextView) listView.getChildAt(i).findViewById(R.id.TextUintID);
    TextView TUintTwoID = (TextView) listView.getChildAt(i).findViewById(R.id.UintTwoID);
    TextView UintTwoPriceV = (TextView) listView.getChildAt(i).findViewById(R.id.UintTwoPrice);
    TextView Add_Units_CountASDV = (TextView) listView.getChildAt(i).findViewById(R.id.Add_Units_Count);

}



Please Help Me
Posted
Updated 14-Feb-20 12:38pm
Comments
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

thank you the solution in the line

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900