خرید بک لینک

Vote count: 0

i need to show 2 column textview using gridview inside expandablelistview.But when i select group one the child item retu many duplicate item.I want to remove the duplicate items.I've tried to find a solution but i am caot find the solution.How can i solve this?

Expandable Adapter

public class Expendable_Adapter extends BaseExpandableListAdapter {

    private Context _context;
    TableLayout tableLayout;
    //private  List<String> _listDataHeader; // header titles
    private List<Expendable_Model> _listDataHeader;
    // child data in format of header title, child title
    //private HashMap<String, List<String>> _listDataChild;
    private List<ExpendableChild_Model> _listDataChild;
    List<ExpendableChild_Model>listchild;

    public Expendable_Adapter(Context context, List<Expendable_Model> listDataHeader,
                              List<ExpendableChild_Model> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
        // this._listImageData=listImageData;
    }


    @Override
    public Object getChild(int groupPosition, int childPosititon) {
//        retu this._listDataChild.get(this._listDataHeader.get(groupPosition))
//                .get(childPosititon);

        retu _listDataChild.get(groupPosition).getChild().get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        retu childPosition;
    }

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

        final String childText = (String) getChild(groupPosition, childPosition);


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

        /*TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
        txtListChild.setText(childText);*/
        //convertView = LayoutInflater.from(_context).inflate(R.layout.list_item,null);
        

        GridView gridView = (GridView)convertView.findViewById(R.id.gridView1);
        gridView.setAdapter(new Grid_Adapter(_context,childText,groupPosition,childPosition));
        Log.d("GridAdapter", String.valueOf(_listDataChild));
        Log.d("childText :", childText );
        retu convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
//        retu childList.get(headerList.get(groupPosition))
//                .size();
        retu _listDataChild.get(groupPosition).getChild().size();
    }

    @Override
    public Expendable_Model getGroup(int groupPosition) {
        retu this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        retu this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        retu groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {


        String headerTitle = getGroup(groupPosition).getGroup();
        int headerIcon = getGroup(groupPosition).getIcon();
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        /*Typeface regular = Typeface.createFromAsset(_context.getAssets(),
                "fonts/HelveticaNeue-Medium.otf");
        lblListHeader.setTypeface(regular, Typeface.NORMAL);*/
        ImageView iconex = (ImageView) convertView.findViewById(R.id.iconex);
        lblListHeader.setText(headerTitle);
        iconex.setBackgroundResource(headerIcon);

     /*   ImageView imageView = (ImageView) convertView.findViewById(R.id.iconex);
       // int imageId = this.groupImages.get(groupPosition);
        imageView.setImageResource();*/

        retu convertView;
    }

    @Override
    public boolean hasStableIds() {
        retu false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        retu true;
    }

}

Grid Adapter

package com.example.content.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.content.Model.ExpendableChild_Model;
import com.example.content.R;

import java.util.List;

/**
 * Created by SMK Telkom SP Malang on 29/07/2016.
 */
public class Grid_Adapter extends BaseAdapter{

    //List<ExpendableChild_Model> listDataChild = new ArrayList<>();

    List<ExpendableChild_Model> child;
    private Context _context;
    String child2;
    int groupPosition, childPosition;


    public Grid_Adapter(Context context,  String childText,int groupPosition,int childPosition) {
        this._context=context;
        this.child2=childText;
        this.groupPosition = groupPosition;
        this.childPosition = childPosition;
    }


    @Override
    public int getCount() {

        retu child2.length();
    }

    @Override
    public Object getItem(int position) {
        retu position;
    }

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


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        /*
            for(int i = 0;i<listDataChild.get(position).getChild().size();i++) {
                String stringwew = String.valueOf((listDataChild.get(position).getChild()));
                Log.d("StringWEW",stringwew);
                Log.d("Posisi", String.valueOf(position));
                Log.d("ListData", String.valueOf(listDataChild));*/
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.row_grid, null);
        }


                /*TextView tv = (TextView) convertView.findViewById(R.id.text);
                tv.setText((CharSequence) child.get(position).getChild());*/





            // String stringwew = String.valueOf((child.get(position).getChild()));
        TextView tv = (TextView) convertView.findViewById(R.id.text);
            tv.setText(child2);
            Log.d("DataList", String.valueOf(child2));
            Log.d("ChildPosition", String.valueOf(childPosition));




        //}

        retu convertView;
    }
    static class ViewHolder {
        TextView tv;
    }

}
asked 28 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 14 مرداد 1395 ساعت: 8:00

صفحه بندی