Android ExpandableListView notifyDataSetChanged

时间:2016-11-03 12:34:53

标签: android expandablelistview seekbar notifydatasetchanged

我的Android应用程序代码存在问题。 我有一些可扩展的列表视图和一些数据。

2秒后,我会定期使用命令NotifyDataSetChanged来更新我的所有数据。

问题是我有一个搜索栏,如果我改变了进度,那么在这2秒之后,数据就会更新,进度也会不断变化。

我不知道我可以做什么只更新可扩展列表视图中的行但不是全部。

    final Handler handler = new Handler();
    timer3 = new Timer();
    czyUruchomionoTimer=true;
    TimerTask doAsynchronousTask = new TimerTask() {

        @Override
        public void run() {
            handler.post(new Runnable() {
                public void run() {


    exAdpt.notifyDataSetChanged();

                }
            });
        }
    };
    timer3.schedule(doAsynchronousTask, 100, 2000);


  }

以下是我的适配器的代码:

   package akme.akmewiz_new;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ListAdapter_Exp extends BaseExpandableListAdapter {

    private List<List_KategoriaObiekty> catList;
    private Context ctx;
    private LayoutInflater inflater;
    private ExpandableListView list;
    private String numerIP;
    int tempMax = 35;
    int tempMin = 10;
    private String numerID;
    Boolean wejscie = false;
    int max = (tempMax-tempMin)*2 ;
    final private static int DIALOG_LOGIN = 1;


    public ListAdapter_Exp(List<List_KategoriaObiekty> catList, Context ctx, String ip, String ID, Boolean wejscie) {

        this.catList = catList;
        this.ctx = ctx;
        this.inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.numerIP= ip;
        this.numerID = ID;
        this.wejscie=wejscie;
    }


    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return catList.get(groupPosition).getItemList();
    }
    @Override
    public long getChildId(int groupPosition, int childPosition) {
        Object obj =  catList.get(Integer.valueOf(numerID)).getItemList().get(groupPosition+2);
        Lista_menu menus = (Lista_menu) obj;
        return menus.getTabelaNazwaItem(childPosition).hashCode();
    }
    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        ViewHolder holder;
        final int tempgroupPos = groupPosition;
        View v = convertView;
        Object obj =  catList.get(Integer.valueOf(numerID)).getItemList().get(groupPosition+2);
        Lista_menu menus = (Lista_menu) obj;

        if(true){
            holder = new ViewHolder();
            v = inflater.inflate(getLayoutId(ctx,"list_exp_"+menus.getTabelaSposobPrezentacji(childPosition)),null);
            Log.d("TAGS","list_exp_"+menus.getTabelaSposobPrezentacji(childPosition));

            list = (ExpandableListView) parent.findViewById(R.id.listExp);
            if(menus.getTabelaSposobPrezentacji(childPosition).equals("0")) {
                holder.item_nazwa = (TextView) v.findViewById(R.id.item_0_nazwa);
                holder.item_wartosc = (TextView) v.findViewById(R.id.item_0_wartosc);
                Log.d("TAGS","tworze0 "+menus.getTabelaSposobPrezentacji(childPosition));
            }
            if(menus.getTabelaSposobPrezentacji(childPosition).equals("1")) {
                holder.item_nazwa = (TextView) v.findViewById(R.id.item_0_nazwa);
                holder.Seek = (SeekBar) v.findViewById(R.id.seekTemp);
                holder.Lab1 = (TextView) v.findViewById(R.id.tvLabel1);
                holder.Lab3 = (TextView) v.findViewById(R.id.tvLabel3);
                holder.Seek.setTag(childPosition + 1);
                Log.d("TAGS","tworze1 "+menus.getTabelaSposobPrezentacji(childPosition));
            }


            v.setTag(holder);
        }else{
            holder = (ViewHolder) v.getTag();
        }


        if(menus.getTabelaSposobPrezentacji(childPosition).equals("0")){
            holder.item_nazwa.setText(menus.getTabelaNazwaItem(childPosition));
            holder.item_wartosc.setText(menus.getTabelaWartoscItem(childPosition));
            Log.d("TAGS","wpisuje "+menus.getTabelaSposobPrezentacji(childPosition));
        }
        if(menus.getTabelaSposobPrezentacji(childPosition).equals("1")){
            holder.item_nazwa.setText(menus.getTabelaNazwaItem(childPosition));
            holder.Lab1.setText("10.0" + " \u2103");
            holder.Lab3.setText("35.0" + " \u2103");
            holder.Seek.setMax(max);
            Log.d("TAGS","wpisuje "+menus.getTabelaSposobPrezentacji(childPosition));

            holder.Seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    notifyDataSetChanged();
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                                              boolean fromUser) {

                    float przelicznik = (float) ((progress / 2.0) + 10.0);
                    View view = (View) seekBar.getParent();
                    if (view != null) {
                        TextView tvProgress2 = (TextView) view.findViewById(R.id.tvLabel2);
                        TextView tvProgress1 = (TextView) view.findViewById(R.id.tvLabel1);
                        TextView tvProgress3 = (TextView) view.findViewById(R.id.tvLabel3);

                        tvProgress1.setText(Float.toString(tempMin) + " \u2103");
                        tvProgress2.setText(Float.toString(przelicznik) + " \u2103");
                        tvProgress3.setText(Float.toString(tempMax) + " \u2103");
                    }

                    Object obj =  catList.get(Integer.valueOf(numerID)).getItemList().get(tempgroupPos+2);
                    Lista_menu menus = (Lista_menu) obj;

                    String ustaw = Float.valueOf(przelicznik).toString();
                    menus.setTabelaWartoscItem2(ustaw,childPosition);

                }
            });

            String str1 = menus.getTabelaWartoscItem2(childPosition);

            if(wejscie){
                str1 = menus.getTabelaWartoscItem(childPosition);
                wejscie=false;
            }

            int ustaw1 =(int)(( ( ( (Float.parseFloat(str1.replaceAll("\\D+","")))/10)*2)-20));
            holder.Seek.setProgress(ustaw1);


        }



        return v;

        }
    @Override
    public int getChildrenCount(int groupPosition) {
        Object obj =  catList.get(Integer.valueOf(numerID)).getItemList().get(groupPosition+2);
        Lista_menu menus = (Lista_menu) obj;
        return menus.ilosc();
    }
    @Override
    public Object getGroup(int groupPosition) {

        return catList.get(groupPosition+2);
    }
    @Override

    public int getGroupCount() {
        int ilosc = catList.get(Integer.valueOf(numerID)).getItemList().size();
        return ilosc-2;
    }



    @Override
    public long getGroupId(int groupPosition) {
        return catList.get(Integer.valueOf(numerID)).hashCode();
    }
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        GroupViewHolder holder;
        View v = convertView;

        if(v==null || !isExpanded || isExpanded){
            holder = new GroupViewHolder();

            v = inflater.inflate(R.layout.list_group_item_exp,null);
            list = (ExpandableListView) parent.findViewById(R.id.listExp);

            holder.groupName = (TextView) v.findViewById(R.id.groupName);
            holder.groupImage = (ImageView) v.findViewById(R.id.groupImage);
            holder.groupIndicator = (ImageView) v.findViewById(R.id.imageView5);
            holder.groupImage.setTag(groupPosition + 11);
            list.setDividerHeight(8);


        v.setTag(holder);
        }else{
            holder = (GroupViewHolder) v.getTag();

        }


        if(isExpanded){
            holder.groupIndicator.setImageResource(R.mipmap.arrow_g);

        }else{
            holder.groupIndicator.setImageResource(R.mipmap.arrow_d);
        }

        holder.groupName.setTextColor(Color.parseColor("#e3e9e4"));

        list.setDividerHeight(8);

        List<Object> lista = catList.get(Integer.valueOf(numerID)).getItemList();
        Object obj = lista.get(groupPosition + 2);

        v.setBackgroundResource(R.drawable.lista_obiekty_niebieski);

        Lista_menu menu = (Lista_menu) obj;
        String obraz = menu.getObrazek();

        holder.groupImage.setImageResource(getImageId(ctx,"ico_" + obraz));
        holder.groupName.setText(menu.getNazwaGrupy());

        return v;

    }


    @Override
    public boolean hasStableIds() {
        return true;
    }
    public static int getImageId(Context context, String imageName) {
        return context.getResources().getIdentifier("mipmap/" + imageName, null, context.getPackageName());
    }
    public static int getLayoutId(Context context, String name) {
        return context.getResources().getIdentifier("layout/" + name, null, context.getPackageName());
    }
    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }


    class ViewHolder {
        TextView item_nazwa, item_wartosc, Lab1, Lab3, Lab2;
        SeekBar Seek;
    }

    class GroupViewHolder {

        TextView groupName;
        ImageView groupImage, groupIndicator;
    }

}

0 个答案:

没有答案