如何清除listview并添加新的listview

时间:2016-11-24 07:13:19

标签: java android listview

如果清除列表视图,列表视图将会消失。列表视图将从for循环中获取数据。

解决方法:

  • 在任何循环中放置setdaylist.clear()将清除所有列表视图并仅显示一个列表项。

  • 在方法顶部设置它会清除所有列表视图,任何解决方案?

代码:

 public void onDataGotOnline(JSONObject response) {

    DateTime today = new DateTime().withTimeAtStartOfDay();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    try {
        JSONArray currentData = response.getJSONArray("list");
               // setdaylist.clear();
        for (int i = 1; i < 5; i++) {
            DateTime tomorow = today.plusDays(i).withTimeAtStartOfDay();
            String dtStr = fmt.print(tomorow);
            int info = 0;


            for(; info<currentData.length();info++ ){
                JSONObject managedata = currentData.getJSONObject(info);
                String time= managedata.getString("dt_txt");

                if(time.equals(dtStr)){

                    int getResult=info+8;

                    double[] arrayAverageTemp = new double[8];
                    double[] arrayMaxTemp = new double[8];
                    double[] arrayMinTemp = new double[8];
                    int[] arrayWheaterId = new int[8];

                    for (int a = info; a < getResult; a++) {
                        JSONObject datalist = currentData.getJSONObject(i);
                        JSONArray weatherdata = datalist.getJSONArray("weather");
                        JSONObject weatherdata2 = weatherdata.getJSONObject(weatherdata.length() - 1);
                        int id = weatherdata2.getInt("id");

                        JSONObject weather = datalist.getJSONObject("main");
                        double avg_temp = weather.getDouble("temp");
                        double max_temp = weather.getDouble("temp_max");
                        double min_temp = weather.getDouble("temp_min");


                        arrayWheaterId[a-info]=id;
                        arrayAverageTemp[a-info]=avg_temp;
                        arrayMaxTemp[a-info]=max_temp;
                        arrayMinTemp[a-info]=min_temp;
                    }


                    ManageData manageData = new ManageData();
                    double max = manageData.findMax(arrayMaxTemp);
                    double min = manageData.findMin(arrayMinTemp);
                    WheatherData day = new WheatherData();
                    day.setDay("sunday");
                   // int image = convert.covertImage(icon);
                    day.setImage(R.drawable.ic_image_01d);
                    day.setDescrption("asdasd");
                    day.setAvgTemp("14 °c");
                    day.setMaxTemp(max+ "°c");
                    day.setMinTemp(min+ "°c");

                    setdaylist.add(day);


                    adapter.notifyDataSetChanged();

                    //  findMax(arrayMaxTemp);
                    //findMin(arrayMinTemp);
                    //findID(arrayWheaterId);
                    //findaverage(arrayAverageTemp);





                }
            }
        }
    }
    catch (JSONException e){

    }

}

1 个答案:

答案 0 :(得分:0)

从上面的讨论开始。

  • 问题是由于Android studio中的缓存问题造成的。
  • 清理项目并构建它会删除现有缓存。

下面显示的for循环之前的var server = http.createServer(function(request, response) { //Creating websocket server }); server.listen(1337, function() { }); // listen to 1337 port var wIoSocket = io.listen(server); wIoSocket.sockets.on('connection', function (socket) { socket.on('message', function (data) { if (data.video) { writeToDisk(data.video.dataURL, data.video.time+'.webm'); } }); }); function writeToDisk(dataURL, fileName) { var dataURL = dataURL.split(',').pop(); var fileBuffer = new Buffer(dataURL, 'base64'); fs.writeFileSync(fileName, fileBuffer); } 按预期工作。

setdaylist