Android 使用loadmore按钮替换旧数据的ListView

Android 使用loadmore按钮替换旧数据的ListView,android,Android,我正在开发android应用程序,我想用load more按钮在listview中显示json数据,但当我单击load more按钮时,旧数据将被新数据替换,我想同时显示旧数据和新数据。Lihstview应该在下面的代码中显示所有数据的错误 public class Newjava extends Activity { JSONObject jsonobject; JSONArray jsonarray; CustomAdapter1 adapter2; CustomAdapter1 adapt

我正在开发android应用程序,我想用load more按钮在listview中显示json数据,但当我单击load more按钮时,旧数据将被新数据替换,我想同时显示旧数据和新数据。Lihstview应该在下面的代码中显示所有数据的错误

public class Newjava extends Activity {
JSONObject jsonobject;
JSONArray jsonarray;
CustomAdapter1 adapter2;
CustomAdapter1 adapter;
ProgressDialog mProgressDialog;
ArrayList<FeedAddress> arraylist;
String url = "http://xxxx.vdv.com/api/fvn/page1";
String arraymovie = "all";
public String string;
ListView listView;
int i = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    listView = (ListView) findViewById(R.id.list);
    arraylist = new ArrayList<FeedAddress>();
    // Retrive JSON Objects from the given website URL in
    // JSONfunctions.class

    jsonobject = JSONfunctions.getJSONfromURL(url);

    try {
        // Locate the array name
        JSONObject jsonObject1 = jsonobject.getJSONObject("appname");
        jsonarray = jsonObject1.getJSONArray("kfnh");

        for (int i = 0; i < jsonarray.length(); i++) {
            JSONObject post = (JSONObject) jsonarray.getJSONObject(i);
            FeedAddress map = new FeedAddress();
            jsonobject = jsonarray.getJSONObject(i);
            // Retrive JSON Objects
            map.setMovieName(post.getString("movieName"));
            map.setName(post.getString("movieActors"));
            map.setMovieId(post.getString("movieId"));
            String imageUrl = "http://www.xxhbc.com/upload/dv/thumbnail/"
                    + post.getString("moviePhoto")
                    + post.getString("moviePhotoExt");
            map.setImageUrl(imageUrl);
            System.out.println("ldhslhdljh " + imageUrl);
            // Set the JSON Objects into the array
            arraylist.add(map);
        }
    } catch (JSONException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

    Button btnLoadMore = new Button(this);
    btnLoadMore.setText("Load More");

    // Adding Load More button to lisview at bottom
    listView.addFooterView(btnLoadMore);

    // Getting adapter
    adapter = new CustomAdapter1(this, arraylist);
    listView.setAdapter(adapter);

    /**
     * Listening to Load More button click event
     * */
    btnLoadMore.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // Starting a new async task
            i += 1;
            new DownloadJSON().execute();
        }
    });
}

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

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    //   Create a progressdialog
         mProgressDialog = new ProgressDialog(Newjava.this);
         // Set progressdialog title
         mProgressDialog.setTitle("APP Name");
         mProgressDialog.setIcon(R.drawable.ic_launcher);
         // Set progressdialog message
         mProgressDialog.setMessage("Loading...");
         mProgressDialog.setIndeterminate(false);
         // Show progressdialog
         mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // Create the array
        arraylist = new ArrayList<FeedAddress>();
        // Retrive JSON Objects from the given website URL in
        // JSONfunctions.class

        String URL = "http://zvzvs.vczx.com/api/v/page"
                + i;
        System.out.println("new url " + URL);
        jsonobject = JSONfunctions.getJSONfromURL(URL);

        try {
            // Locate the array name
            JSONObject jsonObject1 = jsonobject
                    .getJSONObject("fvvzx");
            jsonarray = jsonObject1.getJSONArray("allmovies");

            for (int i = 0; i < jsonarray.length(); i++) {
                JSONObject post = (JSONObject) jsonarray.getJSONObject(i);
                FeedAddress map = new FeedAddress();
                jsonobject = jsonarray.getJSONObject(i);
                // Retrive JSON Objects
                map.setMovieName(post.getString("movieName"));
                // map.setName(post.getString("movieActors"));
                map.setMovieId(post.getString("movieId"));
                String imageUrl = "http://www.vsv.com/upload/vc/thumbnail/"
                        + post.getString("moviePhoto")
                        + post.getString("moviePhotoExt");
                map.setImageUrl(imageUrl);
                System.out.println("ldhslhdljh " + imageUrl);
                // Set the JSON Objects into the array
                arraylist.add(map);
            }

        } catch (JSONException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void args) {
        // Locate the listview in listview_main.xml
        int currentPosition = listView.getFirstVisiblePosition();

        // Appending new data to menuItems ArrayList
        adapter = new CustomAdapter1(Newjava.this, arraylist);
        listView.setAdapter(adapter);

        // Setting new scroll position
        listView.setSelectionFromTop(currentPosition + 1, 0);
        updateList(string);
    }
}

public void updateList(final String string) {
    // TODO Auto-generated method stub

    listView.setVisibility(View.VISIBLE);
    // mProgressDialog.dismiss();
    listView.setAdapter(new CustomAdapter1(Newjava.this, arraylist));
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1,
                int position, long arg3) {
            // TODO Auto-generated method stub
            // Toast.makeText(getApplicationContext(),"position[]" ,
            // Toast.LENGTH_SHORT).show();
            Object o = listView.getItemAtPosition(position);
            FeedAddress newsData = (FeedAddress) o;
            System.out.println("hgsh " + string);
            System.out.println("next " + newsData.getMovieId());

            Intent intent = new Intent(Newjava.this,
                    SingleMenuItemActivity.class);
            intent.putExtra("feed", newsData.getMovieId());
            intent.putExtra("actor", newsData.getName());
            startActivity(intent);
        }
    });
}
公共类Newjava扩展活动{
JSONObject JSONObject;
JSONArray JSONArray;
客户适配器1适配器2;
客户适配器1适配器;
进程对话框;
ArrayList ArrayList;
字符串url=”http://xxxx.vdv.com/api/fvn/page1";
字符串arraymovie=“全部”;
公共字符串;
列表视图列表视图;
int i=1;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView=(listView)findViewById(R.id.list);
arraylist=新的arraylist();
//在中从给定网站URL检索JSON对象
//JSONfunctions.class
jsonobject=JSONfunctions.getJSONfromURL(url);
试一试{
//找到数组名
JSONObject JSONObject 1=JSONObject.getJSONObject(“appname”);
jsonarray=jsonObject1.getJSONArray(“kfnh”);
for(int i=0;i