Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:14:08+00:00 2026-06-18T03:14:08+00:00

I would like to display the data from MySql in a listview using a

  • 0

I would like to display the data from MySql in a listview using a search parameter in my application.
I’ve succeeded, but the problem I’m having is that every time I push the search button twice, both sets of result data are shown in the ListView, whereas I only want to display the latest set of results.

This is the code I’m using:

public class ListPerusahaan extends ListActivity {
    /** Called when the activity is first created. */

    private static final String TAG_ID = "id";
    private static final String TAG_NAMA = "nama_perusahaan";
    private static final String TAG_PEKERJAAN = "pekerjaan";
    private static final String TAG_ALAMAT= "alamat";
    private static final String TAG_DEADLINE = "deadline";

            EditText keyword;   Button search;  private ProgressDialog pDialog;     ArrayList<HashMap<String, String>> DataList;    // JSONArray  perusahaan = null;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listperusahaan);
        keyword=(EditText)findViewById(R.id.Editsearch);
       search=(Button)findViewById(R.id.search);

       DataList = new ArrayList<HashMap<String, String>>();


        search.setOnClickListener(new View.OnClickListener()
        {

            @Override           public void onClick(View v) {
                // TODO Auto-generated method stub

                if (keyword.getText().toString().length() == 0 ) {

                     Toast toast = Toast.makeText(getApplicationContext(),"Please enter your keyword", Toast.LENGTH_SHORT);
                     toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                     toast.show();
                 }
                else {

                new searchData().execute();

                }
                            }

        });

    }

    @SuppressLint("NewApi")     public class searchData extends AsyncTask<Void, Void, Void>
        {

          /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(ListPerusahaan.this);
            pDialog.setMessage("Loading ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

           @Override
           protected Void doInBackground(Void... params) {
               // TODO Auto-generated method stub

             // ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
              List<NameValuePair> paramemeter = new ArrayList<NameValuePair>();
              paramemeter.add(new BasicNameValuePair("keyword", keyword.getText().toString()));

                JSONObject json = JSONParser.getJSONFromUrl("http://10.0.2.2/appmysql/dataperusahaan.php", paramemeter);

                try{

                    JSONArray  perusahaan = json.getJSONArray("perusahaan");


                    if (perusahaan != null)
                   {
                    for(int i=0;i<perusahaan.length();i++){
                        // HashMap<String, String> map1 = new HashMap<String, String>();

                        JSONObject jsonobj = perusahaan.getJSONObject(i);

                         // Storing each json item in variable
                        String id = jsonobj.getString(TAG_ID);
                        String nama_perusahaan = jsonobj.getString(TAG_NAMA);
                        String pekerjaan = jsonobj.getString(TAG_PEKERJAAN);
                        String alamat = jsonobj.getString(TAG_ALAMAT);
                        String deadline = jsonobj.getString(TAG_DEADLINE);

                       // creating new HashMap
                        HashMap<String, String> map1 = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map1.put(TAG_ID, id);
                        map1.put(TAG_NAMA, nama_perusahaan);
                        map1.put(TAG_PEKERJAAN, pekerjaan);
                        map1.put(TAG_ALAMAT, alamat);
                        map1.put(TAG_DEADLINE, deadline);

                        // adding HashList to ArrayList
                       DataList.add(map1);



                        }


                    }

                    else {

                        Toast toast= Toast.makeText(getApplicationContext(),  "No data found", Toast.LENGTH_SHORT);  
                       toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                       toast.show();
                    }

                }

                catch(JSONException e)        {
                    e.printStackTrace();
                }

               return null;

           }

           @Override
           protected void onPostExecute(Void result) {
               // TODO Auto-generated method stub
              pDialog.dismiss();
            // updating UI from Background Thread
              runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */

                    ListAdapter adapter = new SimpleAdapter(
                            ListPerusahaan.this, DataList,R.layout.row,
                              new String[] { TAG_NAMA, TAG_PEKERJAAN, TAG_ALAMAT, TAG_DEADLINE },
                              new int[] { R.id.nama_perusahaan, R.id.pekerjaan, R.id.alamat,R.id.deadline});

                    // updating listview
                    setListAdapter(adapter);

                     final ListView lv = getListView();
                        lv.setTextFilterEnabled(true);
                        lv.setOnItemClickListener(new OnItemClickListener() {
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                /*
                                @SuppressWarnings("unchecked")
                                HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
                                 Toast.makeText(ListPerusahaan.this, "Perusahaan '" + o.get("nama_perusahaan") + "' was clicked.", Toast.LENGTH_SHORT).show(); 
                                */

                                // getting values from selected ListItem
                                String nama = ((TextView) view.findViewById(R.id.nama_perusahaan)).getText().toString();
                                String pekerjaan = ((TextView) view.findViewById(R.id.pekerjaan)).getText().toString();
                                String alamat = ((TextView) view.findViewById(R.id.alamat)).getText().toString();
                                String deadline = ((TextView) view.findViewById(R.id.deadline)).getText().toString();

                                // Starting new intent
                                Intent in = new Intent(getApplicationContext(), detail_lowongan.class);
                                in.putExtra(TAG_NAMA, nama);
                                in.putExtra(TAG_PEKERJAAN, pekerjaan);
                                in.putExtra(TAG_ALAMAT, alamat);
                                in.putExtra(TAG_DEADLINE, deadline);
                                startActivity(in);
                            }
                        });

                }
            });

           }

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:14:09+00:00Added an answer on June 18, 2026 at 3:14 am

    Edit: in onclick clear DataList

    search.setOnClickListener(){
    ......
    
    DataList.clear(); //in onclick method
    }
    

    I am not sure whether you are looking for this or not…but if you don’t want to allow duplicates in your list try ….

    When the data filled in your list

    Set<type> set=new Hashset(yourlist);
    ArrayList<type> nodupList=new ArrayList<type>();
    noduplist.addAll(set);
    

    using this way it will remove the duplicates in your list

    Edit:
    Try this

    After for loop

    Set<HashMap> set=new HashSet(DataList);
    ArrayList<HashMap> nodupList=new ArrayList<HashMap>();
    nodupList.addAll(set);
    DataList.clear();
    DataList.addAll(nodupList);
    

    try it may help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to display my Query from Mysql on the table. However, my
I'm installing WordNet in MySQL from http://www.semantilog.org/wn2sql.html I'd like to display the data in
I'm trying to display data from two different tables in mysql using PHP and
I have managed to display data in one column table, but would like to
I would like to ask how can I can display only some data from
Take the Winlogon registry section, I would like PowerShell to display the Data value
I would like to display other we pages in my mobile webapp, but some
I'm supposed to make queries from MySql database once a day and display data
I have a simple HTML table display of data that results from an MySQL
I get a random row from a mysql-server using php. I then display some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.