无法更新Listview和notifyDataSetChanged()也无法与SeekBar一起使用

时间:2019-06-27 14:04:42

标签: android android-listview android-seekbar

实现ListView并加载基于listView的第一组数据,基于seekBar onProgressChanged的下一个值应被更新。尝试使用notifyDataSetChanged()和所有解决方案在堆栈中,但不起作用。否则,在加载第二组数据后,如何使Listview刷新,除了notifyDataSetChange以外的任何解决方案,因为只需要更改部分值即可。

SeekBar Code

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

        String number = jsonDates.get(progress);
        System.out.println("number:"+number);

        // Date dateObj = dateFormat.parse(number);

        if(oldIndex != progress){

            transFunction();

            ```customAdapter.notifyDataSetChanged();```

            oldIndex = progress;

        }

        // selectedTxtFld.setText(String.valueOf(progress));

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        //Toast.makeText(getApplicationContext(),"seekbar touch started!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
       // Toast.makeText(getApplicationContext(),"seekbar touch stopped!", Toast.LENGTH_SHORT).show();

    }
});

功能(Api调用代码段)

public Void transFunction(){

 RequestQueue reqQueue = Volley.newRequestQueue(this);

            reqQueue.add(new StringRequest(Request.Method.POST, url, new Response.Listener<String>(){
                @Override
                public void onResponse(String response) {
                    // spinner.setVisibility(View.VISIBLE);

                    Log.d(TAG, response);
                    if (response != null){
                        try {
                            System.out.println("We are in JsonObject");
                            JSONObject jsonObject = new JSONObject(response);
                            System.out.println("Got Json Object"+jsonObject);

                           // Arrays.fill(nameString, null);
                            absValuesArray.clear();
                            diffValuesArray.clear();
                            currValArray.clear();
                            prevValArray.clear();
                            jsonDates.clear();
                            indData.clear();

       ListView listView = (ListView)  findViewById(R.id.mobile_list);
                            listView.setAdapter(customAdapter);

}

自定义适配器

class CustomAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return nameString.length;
        }

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

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

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {

            view = getLayoutInflater().inflate(R.layout.custom_layout,null);

//            ImageView

            if (i % 2 == 1) {
                view.setBackgroundColor(Color.parseColor("#E1E1E1F0"));
            } else {
                view.setBackgroundColor(Color.parseColor("#ffffff"));
            }


            System.out.println("nameString_lenth"+nameString.length);
            System.out.println("currArrayObject"+currArrayObject.length);
            System.out.println("diffArrayObject"+diffArrayObject.length);

            TextView textView_name = (TextView)view.findViewById(R.id.textview);
            TextView textView_current = (TextView)view.findViewById(R.id.textview2);
            TextView textView_difference = (TextView)view.findViewById(R.id.textview3);
            ImageView transImageView = (ImageView)view.findViewById(R.id.transimage);


            textView_name.setText(nameString[i]);
            textView_current.setText(currArrayObject[i]);
            textView_difference.setText(diffArrayObject[i]);
            //transImageView.setImage =


            return view;
        }
    }

1 个答案:

答案 0 :(得分:0)

我看到两个问题:

1)您不应在每次调用cbind(df1[1:2], t(apply(df1[-c(1:2)], 1, function(x) df$b[match(names(x[x!=0]), df$a)]))) # rchX frqX 1 2 3 #1 0.5621890547 0.9253731343 F K L #2 0.5522388060 0.9253731343 C F K #3 0.5522388060 0.9154228856 F K R #4 0.5472636816 0.9651741294 C F L #5 0.5472636816 0.9552238806 F L R #6 0.5472636816 0.8756218905 F L O #7 0.5422885572 0.9552238806 C F R #8 0.5422885572 0.8905472637 F J L #9 0.5373134328 0.9004975124 E F L #10 0.5373134328 0.8507462687 F H L 方法时将适配器设置为ListView。您需要设置适配器一次。初始化transFunction时更可取。

2)您的ListView实现不正确。您不返回商品,也不返回itemId。您应该执行以下操作:

Adapter

tutorial显示了一个示例,说明如何将ListView与BaseAdapter一起使用。