Java 如何不再加载所有ListView项目?

Java 如何不再加载所有ListView项目?,java,android,android-listview,parse-platform,onscrolllistener,Java,Android,Android Listview,Parse Platform,Onscrolllistener,我正在使用Parse.com框架,最近我在代码中添加了一个load more(onScroll)列表视图。但我发现,每当加载更多进程开始时,甚至之前的项目也会再次加载。当我添加query.setSkip(someCustomSkip)时,在加载更多进程之后,它只会删除没有(someCustomSkip)编号的项目 您知道如何使用query.setSkip()吗;方法,并保存原始的 1) ListView的第一个位置,在滚动到第五个位置之前query.setLimit(mListView.getC

我正在使用Parse.com框架,最近我在代码中添加了一个load more(onScroll)列表视图。但我发现,每当加载更多进程开始时,甚至之前的项目也会再次加载。当我添加
query.setSkip(someCustomSkip)时,在加载更多进程之后,它只会删除没有(someCustomSkip)编号的项目

您知道如何使用query.setSkip()吗;方法,并保存原始的

1) ListView的第一个位置,在滚动到第五个位置之前
query.setLimit(mListView.getCount+5)

query.setLimit(mListView.getCount+5
)“>

2) 滚动到限制位置后的ListView。它将我抛出到此位置,并设置跳过-隐藏前5项

也是我代码的一部分,这对这个问题很重要:

public class Fragment1 extends Fragment {
    static ListView mListView;
    static AnimalAdapter mAdapter;
    static ProgressBar mProgressBar;
    static EditText mEditText;
    static LayoutInflater inflater;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        final View rootView = inflater.inflate(R.layout.animalsfrag, container, false);
        mListView = (ListView)rootView.findViewById(R.id.animal_list);

        View header = getActivity().getLayoutInflater().inflate(R.layout.header, null);

        header.setPadding(2, 8, 4, 2);
        mListView.setVisibility(View.INVISIBLE);
        mListView.requestFocus();
        mListView.addHeaderView(header); 

        View footie = getActivity().getLayoutInflater().inflate(R.layout.footer, null);
        mListView.addFooterView(footie);
        footie.setVisibility(View.INVISIBLE);


        mProgressBar = (ProgressBar) rootView.findViewById (R.id.loading_animals);
        mProgressBar.setVisibility(View.VISIBLE);

        RemoteDataTask task = new RemoteDataTask();
        task.execute();



        return rootView;
    }



    public void updateData() { //method, which updates my data
         mListView = (ListView)getView().findViewById(R.id.animal_list);     
   final ParseQuery<Animal> query = ParseQuery.getQuery(Animal.class);


    query.setCachePolicy(CachePolicy.NETWORK_ONLY);
    query.orderByAscending("animal");


    query.setLimit(mListView.getCount() + 5);
    if (mListView.getCount() > 5) {
        query.setSkip(5);
    }

    query.findInBackground(new FindCallback<Animal>() {

        @Override
          public void done(List<Animal> animals, ParseException error) {

              if(animals != null){
                  mAdapter.clear();

                mProgressBar = (ProgressBar) getView().findViewById (R.id.loading_animals);
               mProgressBar.setVisibility(View.INVISIBLE);
             RelativeLayout footie = (RelativeLayout) getView().findViewById(R.id.footerview);  
            footie.setVisibility(View.VISIBLE);

            for (int i = 0; i < animals.size(); i++) {


                      mAdapter.add(animals.get(i));







                  }  
              }  
            }
         }); 
    } 




     private class RemoteDataTask extends AsyncTask<Void, Void, Void> {


         @Override
            protected void onPreExecute() {
                super.onPreExecute();  }

         @Override
            protected Void doInBackground(Void... params) {

                return null;



         }


         @Override
            protected void onPostExecute(Void result) {


               mListView = (ListView) getView().findViewById(R.id.animal_list);

               mEditText = (EditText) getView().findViewById(R.id.search_animal);

               mAdapter = new AnimalAdapter(getActivity(), new ArrayList<Animal>());

               mListView.setVisibility(View.VISIBLE);
               mListView.setTextFilterEnabled(true);
               mListView.setAdapter(mAdapter);




               mListView.setOnScrollListener(new OnScrollListener() { 
      //my OnScrollListener

                    @Override
                    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                            int totalItemCount) {
                        final int lastItem = firstVisibleItem + visibleItemCount;
                        if(lastItem == totalItemCount) {




                        if (mListView.getCount() > 20) {

                            RelativeLayout footie = (RelativeLayout) getView().findViewById(R.id.footerview);

                            mListView.removeFooterView(footie);

                              }





                            else{

                                updateData();


                            }

                        }

                    }


                    @Override
                    public void onScrollStateChanged(AbsListView view,
                            int scrollState) {

                        if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
                            View currentFocus = getActivity().getCurrentFocus();
                            if(currentFocus != null) {
                                currentFocus.clearFocus();
                            }
                        }



                    }

                });
               mListView.setAdapter(mAdapter);

                mEditText.addTextChangedListener(new TextWatcher(){

                    @Override
                    public void afterTextChanged(Editable s) {}

                    @Override
                    public void beforeTextChanged(CharSequence s,
                            int start, int count, int after) {}

                    @Override
                    public void onTextChanged(CharSequence s, int start,
                            int before, int count) {

                        System.out.println("Text ["+s+"]");
                        mAdapter.getFilter().filter(s.toString());  
                        }
                });

               }

            }
         }
公共类Fragment1扩展了Fragment{
静态列表视图;
静态动物适应器;
静态进度条;
静态编辑文本;
静态充气机;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
最终视图根视图=充气机。充气(R.layout.animalfrag,container,false);
mListView=(ListView)rootView.findViewById(R.id.animal_列表);
视图标题=getActivity().GetLayoutFlater().inflate(R.layout.header,null);
标题。设置填充(2,8,4,2);
mListView.setVisibility(View.INVISIBLE);
mListView.requestFocus();
mListView.addHeaderView(标题);
视图footie=getActivity().getLayoutFlater().inflate(R.layout.footer,null);
mListView.addFooterView(footie);
footie.setVisibility(视图不可见);
mProgressBar=(ProgressBar)rootView.findviewbyd(R.id.loading\u动物);
mProgressBar.setVisibility(View.VISIBLE);
RemoteDataTask任务=新的RemoteDataTask();
task.execute();
返回rootView;
}
public void updateData(){//方法,用于更新我的数据
mListView=(ListView)getView().findViewById(R.id.animal_列表);
final ParseQuery=ParseQuery.getQuery(Animal.class);
query.setCachePolicy(仅限于CachePolicy.NETWORK_);
查询:orderByAscending(“动物”);
query.setLimit(mListView.getCount()+5);
如果(mListView.getCount()>5){
查询.setSkip(5);
}
findInBackground(新的FindCallback(){
@凌驾
公共作废完成(列出动物,ParseException错误){
如果(动物!=null){
mAdapter.clear();
mProgressBar=(ProgressBar)getView().findViewById(R.id.loading_动物);
mProgressBar.setVisibility(视图.不可见);
RelativeLayout footie=(RelativeLayout)getView().findViewById(R.id.footerview);
footie.setVisibility(视图可见);
对于(int i=0;i20){
RelativeLayout footie=(RelativeLayout)getView().findViewById(R.id.footerview);
mListView.removeFooterView(footie);
}
否则{
更新数据();
}
}
}
@凌驾
CrollStateChanged上的公共无效(AbsListView视图,
int(滚动状态){
如果(滚动\状态\触摸\滚动==滚动状态){
查看currentFocus=getActivity().getCurrentFocus();
if(currentFocus!=null){
currentFocus.clearFocus();
}
}
}
});
mListView.setAdapter(mAdapter);
mEditText.addTextChangedListener(新的TextWatcher(){
@凌驾
公共无效后文本更改(可编辑的s){}
@凌驾
更改前的公共无效文本(字符序列,
int start,int count,int after){}
@凌驾
public void onTextChanged(字符序列,int start,
前整数,整数计数){
System.out.println(“Text[“+s+”]);
mAdapter.getFilter().filter(s.toString());
}
});
}
}
}
谢谢你
ParseQueryAdapter<ParseObject> adapter =
  new ParseQueryAdapter<ParseObject>(this, new ParseQueryAdapter.QueryFactory<ParseObject>() {
    public ParseQuery<ParseObject> create() {
      // Here we can configure a ParseQuery to our heart's desire.
      ParseQuery query = new ParseQuery("Band");
      query.whereContainedIn("genre", Arrays.asList({ "Punk", "Metal" }));
      query.whereGreaterThanOrEqualTo("memberCount", 4);
      query.orderByDescending("albumsSoldCount");
      query.setCachePolicy(ParseQuery.CachePolicy.CACHE_ELSE_NETWORK)
      return query;
    }
  });
 L3.setOnScrollListener(new OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view,
                    int scrollState) { // TODO Auto-generated method stub
                int threshold = 1;
                int count = L3.getCount();

                if (scrollState == SCROLL_STATE_IDLE) {
                    if (L3.getLastVisiblePosition() >= count
                            - threshold) {
                        // Execute LoadMoreDataTask AsyncTask

                    //  Toast.makeText(getApplicationContext(), count- threshold+"", 300).show();

                        if(L3.getLastVisiblePosition()+ threshold <numb)
                        {
                            //Toast.makeText(getApplicationContext(), L3.getLastVisiblePosition()+"", 300).show();
                             new LoadMoreDataTask().execute();
                        }
                        else
                        {
                            Toast.makeText(getApplicationContext(), "لا توجد مزيد من النتائج حاليآ...", 300).show();
                        }

                    }
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
                // TODO Auto-generated method stub

            }

        });