mardi 25 août 2015

Expandable listview not showing the child in android

I have created an Expandable listview using sqlite database. There are 8 columns in database. I want to display these items in this expandable listview. There are separate layout created for header and children. My header part is clear but while clicking any of the item not expanding and not showing the child part. Please help me to resolve this problem

Getview child code is given below

private List<Client> mClientList; 

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent)
{       

    View view=convertView;

    if (view == null) 
    {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = infalInflater.inflate(R.layout.client_list_sub_items, null);
    }

  Client client=(Client)getChild(groupPosition, childPosition);

  TextView txtListAddress = (TextView) view
            .findViewById(R.id.lblListAddress); 
  txtListAddress.setText(client.getName());

  TextView txtListLandmark=(TextView)view.findViewById(R.id.lblListLandMark);
  txtListLandmark.setText(client.getLandMark());

  TextView txtListCity=(TextView)view.findViewById(R.id.lblListCity);
  txtListCity.setText(client.getCity());

  TextView txtListPhone=(TextView)view.findViewById(R.id.lblListPhone);
  txtListPhone.setText(client.getPhone());

  return view;
}

@Override
public int getChildrenCount(int groupPosition) 
{
    List<Client> clList = mClientList.get(groupPosition).getClientList();
    return clList.size();
}

This is my client class

private List<Client> clientList = new ArrayList<Client>();

public Client() {}

public Client(String person_name, String office, String address, String landmark, String city, String phone,
        String mobileNum, String email)
{
    this.mName=person_name;
    this.officeName=office;
    this.address=address;
    this.landMark=landmark;
    this.city=city;
    this.phone=phone;
    this.mobile=mobileNum;
    this.eMail=email;
}

public long getId()
{
    // TODO Auto-generated method stub
    return mId;
}

public String getName()
{
    // TODO Auto-generated method stub
    return mName;
}
public String getOfficeName()
{
    return officeName;
}

public String getAddress()
{
    return address;
}
public String getLandMark()
{
    return landMark;
}

public String getCity()
{
    return city;
}
public String getPhone()
{
    return phone;
}
public String getMobile()
{
    return mobile;
}
public String geteMail()
{
    return eMail;
}

public void setName(String strName) 
{
    this.mName=strName;

}

public void setAddress(String strAddress)
{
    this.address=strAddress;

}

public void setId(long _id)
{
    this.mId=_id;       
}

public void setHouseName(String office) 
{
    this.officeName=office;

}

public List<Client> getClientList()
{
      return clientList;
}

public void setClientList(List<Client> clientList) 
{
      this.clientList = clientList;
}

public void setLandMark(String landMark) 
{
    this.landMark=landMark;

}

public void setCity(String city)
{
    this.city=city;

}

}

MainActivity updating the listview

expListView=(ExpandableListView)findViewById(R.id.listClient);
    mListClient=getAllClient();

    if(mListClient != null && !mListClient.isEmpty()) 
    {
        expListView.invalidateViews();
        client_adapter = new ClientDAOHeader(this, mListClient);
        expListView.setAdapter(client_adapter);
    }
}

private List<Client> getAllClient() 
{
    List<Client> listAllGroup = new ArrayList<Client>();

    Cursor cursor = sdb.query(DatabaseHelper.TABLE_CLIENT_MASTER, mAllColumns,
            null, null, null, null, null);
    if (cursor != null)
    {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) 
        {
            Client client = cursorToClient(cursor);
            listAllGroup.add(client);
            cursor.moveToNext();
        }

        // make sure to close the cursor
        cursor.close();
    }
    return listAllGroup;
}

private Client cursorToClient(Cursor cursor)
{
    Client brnd = new Client();
    brnd.setId(cursor.getLong(0));
    brnd.setHouseName(cursor.getString(1));
    brnd.setName(cursor.getString(2));
    brnd.setAddress(cursor.getString(3));
    brnd.setLandMark(cursor.getString(4));
    brnd.setCity(cursor.getString(5));


    return brnd;
}

Aucun commentaire:

Enregistrer un commentaire