Skip to main content

Custom listview





As the simple ListView, custom ListView also uses Adapter classes which added the content from data source (such as string array, array, database etc). Adapter bridges data between an AdapterViews and other Views

Clu List Xml code:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="10dp"
    android:divider="@android:color/transparent"

    android:padding="16dp"
    android:id="@+id/list"
    android:orientation="vertical"
    tools:context="com.deeparora.po.CluList">


</ListView>




Java code for CLU List:

package com.deeparora.po;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CluList extends AppCompatActivity {
    ListView listView;
   ArrayList<UserActivity> userList;
    CustomAdapter adapter;
    UserActivity user;
    List<User> data;
    //ArrayList<UserActivity> data1;
    TextView txt;

    void initlist() {



     //   adapter = new CustomAdapter(this, R.layout.listitem, userList);
      //  listView.setAdapter(adapter);


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_clu_list);
        Intent rcv = getIntent();
      //txt = (TextView) findViewById(R.id.textView43);
        String id = rcv.getStringExtra("keyName");
        //Toast.makeText(getApplicationContext(), id+" no", Toast.LENGTH_LONG).show();
        listView = (ListView) findViewById(R.id.list);
Log.e("kp",id);


         new AsyncLogin1().execute(id);



    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {


        // Explict Way
        // groupId , itemId, order, title
        /*menu.add(1,101,0,"All Songs");
        menu.add(1,102,0,"Artists");
        menu.add(2,201,0,"Recently Played");
        menu.add(2,202,0,"Favourites");*/

        // Implict Way | IOC (Inversion Of Control)

        getMenuInflater().inflate(R.menu.menu,menu);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        //int gid = item.getGroupId();
        int id = item.getItemId(); // fetch the id on which user has done selection

        /*switch (id){
            case 101:
                Toast.makeText(this,"You Selected All Songs",Toast.LENGTH_LONG).show();
                break;
            case 102:
                Intent intent = new Intent(ActivityOne.this,ActivityTwo.class);
                startActivity(intent);
                break;
            case 201:
                break;
            case 202:
                break;
        }*/

        switch (id){
            case R.id.allSongs:
                Toast.makeText(this,"Logout",Toast.LENGTH_LONG).show();
                SharedPreferences sp =getSharedPreferences("loginpref",MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.clear();
                editor.commit();
                finish();
                Intent intent = new Intent(CluList.this, POMainActivity.class);
                startActivity(intent);
                break;
            case R.id.contact:
                Intent intent1 = new Intent(CluList.this, CONTACT.class);
                startActivity(intent1);
                break;
            case R.id.aboutus:
                Intent intent2 = new Intent(CluList.this, Aboutus.class);
                startActivity(intent2);
                break;
        }

        return super.onOptionsItemSelected(item);
    }
    private class AsyncLogin1 extends AsyncTask<String, String, String> {
        ProgressDialog pdLoading = new ProgressDialog(CluList.this);
        HttpURLConnection conn;
        URL url = null;

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

            //this method will be running on UI thread
            pdLoading.setMessage("\tLoading...");
            pdLoading.setCancelable(false);
            pdLoading.show();

        }

        @Override
        protected String doInBackground(String... params) {
            String response = params[0];



            StringBuilder sbk = new StringBuilder();
            try {
                //String urla = "http://192.168.42.66:8080/clu.php";
                String urla = "http://202.164.39.172:2345/test/training/POREPORT/clu.php";
                String data1 = "";
                URL x = new URL(urla);
                HttpURLConnection connection = (HttpURLConnection) x.openConnection();
                connection.setRequestMethod("POST");
                connection.setDoOutput(true);
                connection.setDoInput(true);
                OutputStream OS = null;

                OS = connection.getOutputStream();

                BufferedWriter bufferedWriter = null;

                bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS, "UTF-8"));
                data1 = URLEncoder.encode("Id", "UTF-8") + "=" + URLEncoder.encode(response, "UTF-8");

                bufferedWriter.write(data1);
                bufferedWriter.flush();
                bufferedWriter.close();
                OS.close();
                //fetching response
                InputStreamReader inp = new InputStreamReader(connection.getInputStream());

                Scanner scnrp = new Scanner(inp);
                while (scnrp.hasNext()) {
                    sbk.append(scnrp.nextLine());

                }
                // return sbk.toString();
            } catch (Exception e) {

                Log.d("tag", e + "");
            }
            //   return sbk.toString();

            return sbk.toString();
        }
        // Pass data to onPostExecute method


        @Override
        protected void onPostExecute(String result) {

            //this method will be running on UI thread
          //  Toast.makeText(getApplicationContext(), result + "", Toast.LENGTH_LONG).show();
            pdLoading.dismiss();
            String country="";
            userList = new ArrayList<>();
            /// pdLoading.dismiss();
            try {
                //JSONObject jobj = new JSONObject( URLDecoder.decode( result, "UTF-8" ));
                JSONArray jArray = new JSONArray(result);
              //  user = new UserActivity();
                Log.e("jj7", result);
                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject json_data = jArray.getJSONObject(i);
                    user = new UserActivity();


                     user.setClu_id(json_data.getString("Id"));
                     user.setClu_name(json_data.getString("CLUApplyName"));
                     user.setClu_licence(json_data.getString("Name_of_applicant"));
                    user.setClu_district(json_data.getString("District"));




                    userList.add(user);
                 // country = json_data.getString("District");
                    //Log.e("jj89", country);
                    //data.add(user);
                }


                adapter = new CustomAdapter(getApplication(), R.layout.listitem, userList);
                adapter.notifyDataSetChanged();
                listView.setAdapter(adapter);
//txt.setText(user.getClu_name());
               // Log.e("j90", userList + "");

                //adapter.setDropDownViewResource(R.layout.spinner_textview);
                // sp2.setAdapter(adapter);
            }

            catch (JSONException e) {
                Toast.makeText(CluList.this, e.toString(), Toast.LENGTH_LONG).show();
            }

        }


    }


}

Comments

Popular posts from this blog

Variables

Variables The main way to store information in the middle of a PHP program is by using a variable. Here are the most important things to know about variables in PHP. All variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment. Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right. Variables can, but do not need, to be declared before assignment. Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. Variables used before they are assigned have default values. PHP does a good job of automatically converting types from one to another when necessary. PHP variables are Perl-like. PHP has a total of eight data types which we use to construct our variables − Integers  − are whole numbers, without a decima...

SQL Server - INTERSECT Operator

Description The SQL Server (Transact-SQL) INTERSECT operator is used to return the records that are in common between two SELECT statements or data sets. If a record exists in one query and not in the other, it will be omitted from the INTERSECT results. It is the intersection of the two SELECT statements. Intersect Query Explanation:  The INTERSECT query will return the records in the blue shaded area. These are the records that exist in both Dataset1 and Dataset2. Each SELECT statement within the SQL Server INTERSECT must have the same number of columns in the result sets with similar data types. Syntax The syntax for the NTERSECT operator in SQL Server (Transact-SQL) is: SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditions] INTERSECT SELECT expression1, expression2, ... expression_n FROM tables [WHERE conditions]; Parameters or Arguments expressions The columns or calculations that you wish to compare between the two SELECT ...

About Application

The product is supposed to be an open source application, developed under the PRSC(Punjab Remote Sensing Centre)organization, for the usage of PUDA(Punjab Urban Planning and Development Authority ). It is An android based system implementing client-server model. The Po portal System provides simple mechanism for the Planning officer to share  truly verified report. The following are the main features that are included in the application are: Common platform support: Offers operating support for most of the known and commercial operating systems i.e. android operating system. Number of users being supported by the system: Though the number is precisely not mentioned but the system is able to support a large number of online users at a time. Search: search for the pending list of the cases assigned is generally by logging in to the application. Id system: provides each officer with a unique Id which is sent at the time of report submission. Verification  section: Verif...