简体   繁体   中英

How to add Elements to ListView in Android

Here i get data from MySql using JSON and List it in the ListView but i want to add more data's to the same ListView at the end of ListView..

Here is my Android Code:

 public void getLocalJobs() {
    String url = ConfigCuboid.GET_JOBS_LOCAL;
    String url1 = Tags;
    String URL = url + url1;
    StringRequest stringRequest = new StringRequest(URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            showJSONLocal(response);
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

@TargetApi(Build.VERSION_CODES.M)
private void showJSONLocal(String response) {
    ParseJSONLocal pj = new ParseJSONLocal(response);
    pj.parseJSONLocal();

    CustomListLocal c1 = new CustomListLocal(this, ParseJSONLocal.job_local_id, ParseJSONLocal.user_names, ParseJSONOnline.job_typess, ParseJSONLocal.job_titles, ParseJSONLocal.job_works,
            ParseJSONLocal.job_dates, ParseJSONLocal.job_months, ParseJSONLocal.job_years,
            ParseJSONLocal.job_times, ParseJSONLocal.job_periods, ParseJSONLocal.job_areas, ParseJSONLocal.job_rates,
            ParseJSONLocal.user_ids, ParseJSONLocal.job_detailss, ParseJSONLocal.image, ParseJSONLocal.regtoken
            , ParseJSONLocal.verify);
    listViewWork.setAdapter(c1);

    listViewWork.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int poss, long id) {
            Intent is = new Intent(getApplicationContext(), WorkProfileLocal.class);
            is.putExtra("Positions", poss);
            startActivity(is);
        }
    });


    listViewWork.setOnScrollListener(new AbsListView.OnScrollListener() {

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

        }

        @Override
        public void onScroll(AbsListView view,
                             int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            final int lastItem = firstVisibleItem + visibleItemCount;
            if (lastItem == totalItemCount) {
                LoadLocalList();
            }

        }


    });
}

At the setOnScrollListener the ListView is erased and new list of data is added,but i need to add data to the existing ListView itself. I just want to know how to adapter to this stuff.. please someone help me..

Step 1: Create custom layout. paste it to your layout folder.

Step 2: Create BaseAdapter class and bind your custom layout to BaseAdapter's getView() method.

Step 3: Set Adapter to your ListView in your activity : MainActivity.

That set. Study about: Base Adapter : https://developer.android.com/reference/android/widget/BaseAdapter.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM