Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将新项目添加到listview中,但不显示“;“跳跃”;将操作返回给用户,但保持在原始项目位置_Android_Android Listview - Fatal编程技术网

Android 将新项目添加到listview中,但不显示“;“跳跃”;将操作返回给用户,但保持在原始项目位置

Android 将新项目添加到listview中,但不显示“;“跳跃”;将操作返回给用户,但保持在原始项目位置,android,android-listview,Android,Android Listview,嗨,我用这个让ListView从顶部向后滚动。然而,从用户的角度来看,ListView从顶部项目跳回原始项目。如果有一种方法可以实现平滑滚动(无跳变)以加载更多项目,这将更好,这意味着在添加新项目时ListView将保持在原始项目位置,而不会看到跳变动作。有可能吗? 我使用setSelection(索引)跳回下面的原始项 for (int i = 0; i < jsonArray.length(); i++) { String userName =

嗨,我用这个让ListView从顶部向后滚动。然而,从用户的角度来看,ListView从顶部项目跳回原始项目。如果有一种方法可以实现平滑滚动(无跳变)以加载更多项目,这将更好,这意味着在添加新项目时ListView将保持在原始项目位置,而不会看到跳变动作。有可能吗? 我使用setSelection(索引)跳回下面的原始项

for (int i = 0; i < jsonArray.length(); i++) {
                    String userName = jsonArray.getJSONObject(i).getString("Username");
                    String messageContent = jsonArray.getJSONObject(i).getString("MessageContent");
                    String timestamp = jsonArray.getJSONObject(i).getString("TimeStamp");
                    String convertedTimestamp;
                    try {
                        convertedTimestamp = convertTimeToLocal(timestamp);
                    } catch (ParseException e) {
                        Log.e(TAG, e.toString());
                        convertedTimestamp = "";
                    }
                    ChatMessage messageObj = new ChatMessage();
                    messageObj.setSenderName(userName);
                    messageObj.setOriginalTimeFormat(timestamp);
                    messageObj.setMessageContent(messageContent);
                    messageObj.setSendTime(convertedTimestamp);

                    chatMessages.add(0, messageObj);
                    chatAdapter.notifyDataSetChanged();
                }

                if (chatMessages.size() != 0) {
                    lastMessageTimestamp = chatMessages.get(0).getOriginalTimeFormat();
                    dataParams.put("TimeStamp", lastMessageTimestamp);

                    chatListView.post(new Runnable() {
                        @Override
                        public void run() {
                            if (requestType == RequestType.FirstRequest)
                                chatListView.setSelection(chatMessages.size() - 1);
                            else
                                chatListView.setSelection(arrayLength);
                            chatListView.post(new Runnable() {
                                @Override
                                public void run() {
                                    upScrollListener.finishLoading();
                                }
                            });
                        }
                    });
                } else {
                    //TODO : add notification message to ask user to enter message
                }
for(int i=0;i
你能不能放一些目前正在使用的代码?别担心,我不应该使用post方法。它被添加是因为其他问题,但在我的案例中不再有用