android - 如何从ListView中删除重复数据

时间:2015-05-22 08:40:22

标签: android sqlite listview

我有一个从db填充的列表视图 像这样:

  • id:1,姓名:Sam,加:印度尼西亚,费率:5
  • id:2,姓名:Bowo,地址:雅加达,费率:5
  • id:1,姓名:Sam,添加:印度尼西亚,费率:3
  • id:2,姓名:Bowo,地址:雅加达,费率:3

它取自同一个数据库,但速率的结果来自不同的查询。 我想删除这些副本只会像这样:

  • id:1,姓名:Sam,加:印度尼西亚,费率:5
  • id:2,姓名:Bowo,地址:雅加达,费率:5

我该怎么做?这可能吗? 谢谢

private class LoadViewTask extends AsyncTask<Void, HashMap<String, String>, Void> {
    private SearchListAdapter adapter;
    // Before running code in separate thread
    @Override
    protected void onPreExecute() {
        String filterRev = "";
        try {
            filterRev = URLEncoder.encode(
                    MainActivity.FILTER_SEARCH_ENTERPRISE, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        final String dummyURL5star = MainActivity.BASE_URL
                + "v_enterprise-select5star.php?filteritem=" + filterRev;
        final String dummyURL4star = MainActivity.BASE_URL
                + "v_enterprise-select4star.php?filteritem=" + filterRev;
        final String dummyURL3star = MainActivity.BASE_URL
                + "v_enterprise-select3star.php?filteritem=" + filterRev;
        final String dummyURL2star = MainActivity.BASE_URL
                + "v_enterprise-select2star.php?filteritem=" + filterRev;
        final String dummyURL1star = MainActivity.BASE_URL
                + "v_enterprise-select1star.php?filteritem=" + filterRev;
        xResult5star = MainActivity.getRequestSelect(dummyURL5star,
                SearchActivity.this);
        xResult4star = MainActivity.getRequestSelect(dummyURL4star,
                SearchActivity.this);

        xResult3star = MainActivity.getRequestSelect(dummyURL3star,
                SearchActivity.this);
        xResult2star = MainActivity.getRequestSelect(dummyURL2star,
                SearchActivity.this);
        xResult1star = MainActivity.getRequestSelect(
                dummyURL1star, SearchActivity.this);

        list = (ListView) findViewById(R.id.lvRowsEnterpriseSearch);
        adapter = new SearchListAdapter(SearchActivity.this, listRow);
        list.setAdapter(adapter);
        registerForContextMenu(list);
        //adapter = (SearchListAdapter) list.getAdapter();

    }

    // The code to be executed in a background thread.
    @Override
    protected Void doInBackground(Void... params) {

            /*final String dummyURL4star = MainActivity.BASE_URL
                    + "v_enterprise-select4star.php?filteritem=" + filterRev;
            final String dummyURL3star = MainActivity.BASE_URL
                    + "v_enterprise-select3star.php?filteritem=" + filterRev;
            final String dummyURL2star = MainActivity.BASE_URL
                    + "v_enterprise-select2star.php?filteritem=" + filterRev;
            final String dummyURL1star = MainActivity.BASE_URL
                    + "v_enterprise-select1star.php?filteritem=" + filterRev;   $*/         

            try {
                jObject5 = new JSONObject(xResult5star);
            JSONArray menuitemArray = jObject5.getJSONArray("venterprise");
            if (panjangList < menuitemArray.length()) {
                for (int i = 0; i < panjangList; i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    map.put(KEY_IDENTERPRISE, menuitemArray.getJSONObject(i)
                            .getString("identerprise").toString());
                    map.put(KEY_NAMAENTERPRISE, menuitemArray.getJSONObject(i)
                            .getString("nama").toString());
                    map.put(KEY_ALAMATENTERPRISE, menuitemArray.getJSONObject(i)
                            .getString("address").toString());
                    map.put(KEY_KATEGORI,
                            menuitemArray.getJSONObject(i).getString("linkkat")
                                    .toString());
                    map.put(KEY_LINK,
                            menuitemArray.getJSONObject(i).getString("linksub")
                                    .toString());
                    map.put(KEY_KAT,
                            menuitemArray.getJSONObject(i).getString("kategori")
                                    .toString());
                    map.put(KEY_SUB,
                            menuitemArray.getJSONObject(i).getString("subkategori")
                                    .toString());
                    map.put(KEY_IDKAT,
                            menuitemArray.getJSONObject(i).getString("idkategori")
                                    .toString());
                    map.put(KEY_IDSUB,
                            menuitemArray.getJSONObject(i)
                                    .getString("idsubkategori").toString());
                    map.put(KEY_THUMB_URL, menuitemArray.getJSONObject(i)
                            .getString("picture").toString());
                    map.put(KEY_HITS,
                            menuitemArray.getJSONObject(i).getString("hit")
                                    .toString());
                    map.put(KEY_NOKONTRAKS, menuitemArray.getJSONObject(i)
                            .getString("nokontrak").toString());
                    map.put(KEY_STAR, "5");
                    publishProgress(map);
                }
            }

                /*
                 * list = (ListView) findViewById(R.id.lvRowsEnterpriseSearch);
                 * adapter = new SearchListAdapter(this, listRow);
                 * list.setAdapter(adapter); registerForContextMenu(list);
                 */
             else {
                sisaList = panjangList - menuitemArray.length();
                for (int i = 0; i < menuitemArray.length(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    map.put(KEY_IDENTERPRISE, menuitemArray.getJSONObject(i)
                            .getString("identerprise").toString());
                    map.put(KEY_NAMAENTERPRISE, menuitemArray.getJSONObject(i)
                            .getString("nama").toString());
                    map.put(KEY_ALAMATENTERPRISE, menuitemArray.getJSONObject(i)
                            .getString("address").toString());
                    map.put(KEY_KATEGORI,
                            menuitemArray.getJSONObject(i).getString("linkkat")
                                    .toString());
                    map.put(KEY_LINK,
                            menuitemArray.getJSONObject(i).getString("linksub")
                                    .toString());
                    map.put(KEY_KAT,
                            menuitemArray.getJSONObject(i).getString("kategori")
                                    .toString());
                    map.put(KEY_SUB,
                            menuitemArray.getJSONObject(i).getString("subkategori")
                                    .toString());
                    map.put(KEY_IDKAT,
                            menuitemArray.getJSONObject(i).getString("idkategori")
                                    .toString());
                    map.put(KEY_IDSUB,
                            menuitemArray.getJSONObject(i)
                                    .getString("idsubkategori").toString());
                    map.put(KEY_THUMB_URL, menuitemArray.getJSONObject(i)
                            .getString("picture").toString());
                    map.put(KEY_HITS,
                            menuitemArray.getJSONObject(i).getString("hit")
                                    .toString());
                    map.put(KEY_NOKONTRAKS, menuitemArray.getJSONObject(i)
                            .getString("nokontrak").toString());
                    map.put(KEY_STAR, "5");

                    publishProgress(map);
                }
                /*
                 * list = (ListView) findViewById(R.id.lvRowsEnterpriseSearch);
                 * adapter = new SearchListAdapter(this, listRow);
                 * list.setAdapter(adapter); registerForContextMenu(list);
                 */

                jObject4 = new JSONObject(xResult4star);
                JSONArray menuitemArray4 = jObject4.getJSONArray("venterprise");
                if (sisaList < menuitemArray4.length()) {
                    for (int i = 0; i < sisaList; i++) {
                        HashMap<String, String> map4 = new HashMap<String, String>();
                        map4.put(KEY_IDENTERPRISE, menuitemArray4.getJSONObject(i)
                                .getString("identerprise").toString());
                        map4.put(KEY_NAMAENTERPRISE, menuitemArray4.getJSONObject(i)
                                .getString("nama").toString());
                        map4.put(KEY_ALAMATENTERPRISE,
                                menuitemArray4.getJSONObject(i)
                                        .getString("address").toString());
                        map4.put(KEY_KATEGORI, menuitemArray4.getJSONObject(i)
                                .getString("linkkat").toString());
                        map4.put(KEY_LINK, menuitemArray4.getJSONObject(i)
                                .getString("linksub").toString());
                        map4.put(KEY_KAT,
                                menuitemArray4.getJSONObject(i)
                                        .getString("kategori").toString());
                        map4.put(KEY_SUB,
                                menuitemArray4.getJSONObject(i)
                                        .getString("subkategori").toString());
                        map4.put(KEY_IDKAT, menuitemArray4.getJSONObject(i)
                                .getString("idkategori").toString());
                        map4.put(KEY_IDSUB, menuitemArray4.getJSONObject(i)
                                .getString("idsubkategori").toString());
                        map4.put(KEY_THUMB_URL, menuitemArray4.getJSONObject(i)
                                .getString("picture").toString());
                        map4.put(KEY_HITS, menuitemArray4.getJSONObject(i)
                                .getString("hit").toString());
                        map4.put(KEY_NOKONTRAKS, menuitemArray4.getJSONObject(i)
                                .getString("nokontrak").toString());
                        map4.put(KEY_STAR, "4");

                        publishProgress(map4);
                    }
                    /*
                     * list = (ListView) findViewById(R.id.lvRowsEnterpriseSearch);
                     * adapter = new SearchListAdapter(this, listRow);
                     * list.setAdapter(adapter); registerForContextMenu(list);
                     */
                } else {

                    for (int i = 0; i < menuitemArray4.length(); i++) {
                        HashMap<String, String> map4 = new HashMap<String, String>();
                        map4.put(KEY_IDENTERPRISE, menuitemArray4.getJSONObject(i)
                                .getString("identerprise").toString());
                        map4.put(KEY_NAMAENTERPRISE, menuitemArray4.getJSONObject(i)
                                .getString("nama").toString());
                        map4.put(KEY_ALAMATENTERPRISE,
                                menuitemArray4.getJSONObject(i)
                                        .getString("address").toString());
                        map4.put(KEY_KATEGORI, menuitemArray4.getJSONObject(i)
                                .getString("linkkat").toString());
                        map4.put(KEY_LINK, menuitemArray4.getJSONObject(i)
                                .getString("linksub").toString());
                        map4.put(KEY_KAT,
                                menuitemArray4.getJSONObject(i)
                                        .getString("kategori").toString());
                        map4.put(KEY_SUB,
                                menuitemArray4.getJSONObject(i)
                                        .getString("subkategori").toString());
                        map4.put(KEY_IDKAT, menuitemArray4.getJSONObject(i)
                                .getString("idkategori").toString());
                        map4.put(KEY_IDSUB, menuitemArray4.getJSONObject(i)
                                .getString("idsubkategori").toString());
                        map4.put(KEY_THUMB_URL, menuitemArray4.getJSONObject(i)
                                .getString("picture").toString());
                        map4.put(KEY_HITS, menuitemArray4.getJSONObject(i)
                                .getString("hit").toString());
                        map4.put(KEY_NOKONTRAKS, menuitemArray4.getJSONObject(i)
                                .getString("nokontrak").toString());
                        map4.put(KEY_STAR, "4");

                        publishProgress(map4);
                    }
                    /*
                     * list = (ListView) findViewById(R.id.lvRowsEnterpriseSearch);
                     * adapter = new SearchListAdapter(this, listRow);
                     * list.setAdapter(adapter); registerForContextMenu(list);
                     */

                    sisaList = sisaList - menuitemArray4.length();

                    jObject3 = new JSONObject(xResult3star);
                    JSONArray menuitemArray3 = jObject3.getJSONArray("venterprise");

                    if (sisaList < menuitemArray3.length()) {
                        for (int i = 0; i < sisaList; i++) {
                            HashMap<String, String> map3 = new HashMap<String, String>();
                            map3.put(KEY_IDENTERPRISE,
                                    menuitemArray3.getJSONObject(i)
                                            .getString("identerprise").toString());
                            map3.put(KEY_NAMAENTERPRISE, menuitemArray3
                                    .getJSONObject(i).getString("nama").toString());
                            map3.put(KEY_ALAMATENTERPRISE, menuitemArray3
                                    .getJSONObject(i).getString("address")
                                    .toString());
                            map3.put(KEY_KATEGORI, menuitemArray3.getJSONObject(i)
                                    .getString("linkkat").toString());
                            map3.put(KEY_LINK, menuitemArray3.getJSONObject(i)
                                    .getString("linksub").toString());
                            map3.put(KEY_KAT, menuitemArray3.getJSONObject(i)
                                    .getString("kategori").toString());
                            map3.put(KEY_SUB, menuitemArray3.getJSONObject(i)
                                    .getString("subkategori").toString());
                            map3.put(KEY_IDKAT, menuitemArray3.getJSONObject(i)
                                    .getString("idkategori").toString());
                            map3.put(KEY_IDSUB, menuitemArray3.getJSONObject(i)
                                    .getString("idsubkategori").toString());
                            map3.put(KEY_THUMB_URL, menuitemArray3.getJSONObject(i)
                                    .getString("picture").toString());
                            map3.put(KEY_HITS, menuitemArray3.getJSONObject(i)
                                    .getString("hit").toString());
                            map3.put(KEY_NOKONTRAKS, menuitemArray3.getJSONObject(i)
                                    .getString("nokontrak").toString());
                            map3.put(KEY_STAR, "3");

                            publishProgress(map3);
                        }
                        /*
                         * list = (ListView)
                         * findViewById(R.id.lvRowsEnterpriseSearch); adapter = new
                         * SearchListAdapter(this, listRow);
                         * list.setAdapter(adapter); registerForContextMenu(list);
                         */
                    } else {

                        for (int i = 0; i < menuitemArray3.length(); i++) {
                            HashMap<String, String> map3 = new HashMap<String, String>();
                            map3.put(KEY_IDENTERPRISE,
                                    menuitemArray3.getJSONObject(i)
                                            .getString("identerprise").toString());
                            map3.put(KEY_NAMAENTERPRISE, menuitemArray3
                                    .getJSONObject(i).getString("nama").toString());
                            map3.put(KEY_ALAMATENTERPRISE, menuitemArray3
                                    .getJSONObject(i).getString("address")
                                    .toString());
                            map3.put(KEY_KATEGORI, menuitemArray3.getJSONObject(i)
                                    .getString("linkkat").toString());
                            map3.put(KEY_LINK, menuitemArray3.getJSONObject(i)
                                    .getString("linksub").toString());
                            map3.put(KEY_KAT, menuitemArray3.getJSONObject(i)
                                    .getString("kategori").toString());
                            map3.put(KEY_SUB, menuitemArray3.getJSONObject(i)
                                    .getString("subkategori").toString());
                            map3.put(KEY_IDKAT, menuitemArray3.getJSONObject(i)
                                    .getString("idkategori").toString());
                            map3.put(KEY_IDSUB, menuitemArray3.getJSONObject(i)
                                    .getString("idsubkategori").toString());
                            map3.put(KEY_THUMB_URL, menuitemArray3.getJSONObject(i)
                                    .getString("picture").toString());
                            map3.put(KEY_HITS, menuitemArray3.getJSONObject(i)
                                    .getString("hit").toString());
                            map3.put(KEY_NOKONTRAKS, menuitemArray3.getJSONObject(i)
                                    .getString("nokontrak").toString());
                            map3.put(KEY_STAR, "3");

                            publishProgress(map3);
                        }
                        /*
                         * list = (ListView)
                         * findViewById(R.id.lvRowsEnterpriseSearch); adapter = new
                         * SearchListAdapter(this, listRow);
                         * list.setAdapter(adapter); registerForContextMenu(list);
                         */

                        sisaList = sisaList - menuitemArray3.length();


                        jObject2 = new JSONObject(xResult2star);
                        JSONArray menuitemArray2 = jObject2
                                .getJSONArray("venterprise");

                        if (sisaList < menuitemArray2.length()) {
                            for (int i = 0; i < sisaList; i++) {
                                HashMap<String, String> map2 = new HashMap<String, String>();
                                map2.put(KEY_IDENTERPRISE, menuitemArray2
                                        .getJSONObject(i).getString("identerprise")
                                        .toString());
                                map2.put(KEY_NAMAENTERPRISE, menuitemArray2
                                        .getJSONObject(i).getString("nama")
                                        .toString());
                                map2.put(KEY_ALAMATENTERPRISE, menuitemArray2
                                        .getJSONObject(i).getString("address")
                                        .toString());
                                map2.put(KEY_KATEGORI,
                                        menuitemArray2.getJSONObject(i)
                                                .getString("linkkat").toString());
                                map2.put(KEY_LINK, menuitemArray2.getJSONObject(i)
                                        .getString("linksub").toString());
                                map2.put(KEY_KAT, menuitemArray2.getJSONObject(i)
                                        .getString("kategori").toString());
                                map2.put(KEY_SUB, menuitemArray2.getJSONObject(i)
                                        .getString("subkategori").toString());
                                map2.put(KEY_IDKAT, menuitemArray2.getJSONObject(i)
                                        .getString("idkategori").toString());
                                map2.put(KEY_IDSUB, menuitemArray2.getJSONObject(i)
                                        .getString("idsubkategori").toString());
                                map2.put(KEY_THUMB_URL, menuitemArray2
                                        .getJSONObject(i).getString("picture")
                                        .toString());
                                map2.put(KEY_HITS, menuitemArray2.getJSONObject(i)
                                        .getString("hit").toString());
                                map2.put(KEY_NOKONTRAKS, menuitemArray2
                                        .getJSONObject(i).getString("nokontrak")
                                        .toString());
                                map2.put(KEY_STAR, "2");

                                publishProgress(map2);
                            }
                            /*
                             * list = (ListView)
                             * findViewById(R.id.lvRowsEnterpriseSearch); adapter =
                             * new SearchListAdapter(this, listRow);
                             * list.setAdapter(adapter);
                             * registerForContextMenu(list);
                             */
                        } else {
                            for (int i = 0; i < menuitemArray2.length(); i++) {
                                HashMap<String, String> map2 = new HashMap<String, String>();
                                map2.put(KEY_IDENTERPRISE, menuitemArray2
                                        .getJSONObject(i).getString("identerprise")
                                        .toString());
                                map2.put(KEY_NAMAENTERPRISE, menuitemArray2
                                        .getJSONObject(i).getString("nama")
                                        .toString());
                                map2.put(KEY_ALAMATENTERPRISE, menuitemArray2
                                        .getJSONObject(i).getString("address")
                                        .toString());
                                map2.put(KEY_KATEGORI,
                                        menuitemArray2.getJSONObject(i)
                                                .getString("linkkat").toString());
                                map2.put(KEY_LINK, menuitemArray2.getJSONObject(i)
                                        .getString("linksub").toString());
                                map2.put(KEY_KAT, menuitemArray2.getJSONObject(i)
                                        .getString("kategori").toString());
                                map2.put(KEY_SUB, menuitemArray2.getJSONObject(i)
                                        .getString("subkategori").toString());
                                map2.put(KEY_IDKAT, menuitemArray2.getJSONObject(i)
                                        .getString("idkategori").toString());
                                map2.put(KEY_IDSUB, menuitemArray2.getJSONObject(i)
                                        .getString("idsubkategori").toString());
                                map2.put(KEY_THUMB_URL, menuitemArray2
                                        .getJSONObject(i).getString("picture")
                                        .toString());
                                map2.put(KEY_HITS, menuitemArray2.getJSONObject(i)
                                        .getString("hit").toString());
                                map2.put(KEY_NOKONTRAKS, menuitemArray2
                                        .getJSONObject(i).getString("nokontrak")
                                        .toString());
                                map2.put(KEY_STAR, "2");

                                publishProgress(map2);
                            }
                            /*
                             * list = (ListView)
                             * findViewById(R.id.lvRowsEnterpriseSearch); adapter =
                             * new SearchListAdapter(this, listRow);
                             * list.setAdapter(adapter);
                             * registerForContextMenu(list);
                             */

                            sisaList = sisaList - menuitemArray2.length();

                            jObject1 = new JSONObject(xResult1star);
                            JSONArray menuitemArray1 = jObject1
                                    .getJSONArray("venterprise");

                            if (sisaList < menuitemArray1.length()) {
                                for (int i = 0; i < sisaList; i++) {
                                    HashMap<String, String> map1 = new HashMap<String, String>();
                                    map1.put(KEY_IDENTERPRISE,
                                            menuitemArray1.getJSONObject(i)
                                                    .getString("identerprise")
                                                    .toString());
                                    map1.put(KEY_NAMAENTERPRISE, menuitemArray1
                                            .getJSONObject(i).getString("nama")
                                            .toString());
                                    map1.put(KEY_ALAMATENTERPRISE, menuitemArray1
                                            .getJSONObject(i).getString("address")
                                            .toString());
                                    map1.put(KEY_KATEGORI, menuitemArray1
                                            .getJSONObject(i).getString("linkkat")
                                            .toString());
                                    map1.put(KEY_LINK,
                                            menuitemArray1.getJSONObject(i)
                                                    .getString("linksub")
                                                    .toString());
                                    map1.put(KEY_KAT, menuitemArray1
                                            .getJSONObject(i).getString("kategori")
                                            .toString());
                                    map1.put(KEY_SUB,
                                            menuitemArray1.getJSONObject(i)
                                                    .getString("subkategori")
                                                    .toString());
                                    map1.put(KEY_IDKAT,
                                            menuitemArray1.getJSONObject(i)
                                                    .getString("idkategori")
                                                    .toString());
                                    map1.put(KEY_IDSUB,
                                            menuitemArray1.getJSONObject(i)
                                                    .getString("idsubkategori")
                                                    .toString());
                                    map1.put(KEY_THUMB_URL, menuitemArray1
                                            .getJSONObject(i).getString("picture")
                                            .toString());
                                    map1.put(KEY_HITS,
                                            menuitemArray1.getJSONObject(i)
                                                    .getString("hit").toString());
                                    map1.put(KEY_NOKONTRAKS, menuitemArray1
                                            .getJSONObject(i)
                                            .getString("nokontrak").toString());
                                    map1.put(KEY_STAR, "1");

                                    publishProgress(map1);
                                }
                                /*
                                 * list = (ListView)
                                 * findViewById(R.id.lvRowsEnterpriseSearch);
                                 * adapter = new SearchListAdapter(this, listRow);
                                 * list.setAdapter(adapter);
                                 * registerForContextMenu(list);
                                 */
                            }
                        }
                    }
                }
            }

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        /*for ( HashMap<String, String> item: listRow)
        {
            publishProgress(item);
        }*/

    return null;
    }

    // Update the progress 
    @Override
    protected void onProgressUpdate(HashMap<String, String>... values) {

        listRow.add(values[0]);

    }

    // after executing the code in the thread
    @Override
    protected void onPostExecute(Void result) {


    }
}

这是列表的代码 适配器是自定义的:

public class SearchListAdapter extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public SearchListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    imageLoader=new ImageLoader(activity.getApplicationContext());
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.search_list_row, null);

    TextView identerprise = (TextView)vi.findViewById(R.id.tvIDEnterprise); 
    TextView enterprise = (TextView)vi.findViewById(R.id.tvEnterprise);
    TextView addenterprise = (TextView)vi.findViewById(R.id.tvAddEnterprise);
    TextView kategori = (TextView)vi.findViewById(R.id.linkkat);
    TextView link = (TextView)vi.findViewById(R.id.linksub);
    TextView tvkat = (TextView)vi.findViewById(R.id.tvkat);
    TextView tvsub = (TextView)vi.findViewById(R.id.tvsub);
    TextView idkat = (TextView)vi.findViewById(R.id.idkat);
    TextView idsub = (TextView)vi.findViewById(R.id.idsub);
    TextView hitS = (TextView)vi.findViewById(R.id.tvHitS);
    TextView starS = (TextView)vi.findViewById(R.id.starS);
    TextView nokontrakS = (TextView)vi.findViewById(R.id.noKontrakS);
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.imageIcon);
    ImageView thumb = (ImageView) vi.findViewById(R.id.hitSearch);
    ImageView star = (ImageView) vi.findViewById(R.id.starSearch);

    HashMap<String, String> hasil = new HashMap<String, String>();
    hasil = data.get(position);

    // Setting all values in listview
    identerprise.setText(hasil.get(SearchActivity.KEY_IDENTERPRISE));
    identerprise.setVisibility(View.INVISIBLE);
    enterprise.setText(hasil.get(SearchActivity.KEY_NAMAENTERPRISE));
    enterprise.setPaintFlags(enterprise.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    addenterprise.setText(hasil.get(SearchActivity.KEY_ALAMATENTERPRISE));
    kategori.setText(hasil.get(SearchActivity.KEY_KATEGORI));
    kategori.setVisibility(View.INVISIBLE);
    link.setText(hasil.get(SearchActivity.KEY_LINK));
    link.setVisibility(View.INVISIBLE);
    tvkat.setText(hasil.get(SearchActivity.KEY_KAT));
    tvkat.setVisibility(View.INVISIBLE);
    tvsub.setText(hasil.get(SearchActivity.KEY_SUB));
    tvsub.setVisibility(View.INVISIBLE);
    idkat.setText(hasil.get(SearchActivity.KEY_IDKAT));
    idkat.setVisibility(View.INVISIBLE);
    idsub.setText(hasil.get(SearchActivity.KEY_IDSUB));
    idsub.setVisibility(View.INVISIBLE);
    hitS.setText(hasil.get(SearchActivity.KEY_HITS));
    hitS.setVisibility(View.INVISIBLE);
    nokontrakS.setText(hasil.get(SearchActivity.KEY_NOKONTRAKS));
    nokontrakS.setVisibility(View.INVISIBLE);
    starS.setText(hasil.get(SearchActivity.KEY_STAR));
    starS.setVisibility(View.INVISIBLE);
    //starS.setVisibility(View.INVISIBLE);

    if(Integer.parseInt(hasil.get(SearchActivity.KEY_HITS))>100)
    {thumb.setImageResource(R.drawable.thumb3);}
    else
    {if(Integer.parseInt(hasil.get(SearchActivity.KEY_HITS))>10)
        {thumb.setImageResource(R.drawable.thumb2);}
        else
        {if(Integer.parseInt(hasil.get(SearchActivity.KEY_HITS))>0)
            {thumb.setImageResource(R.drawable.thumb1);}
            else
            {thumb.setImageResource(R.drawable.thumb);}
        }
    }

    if(Integer.parseInt(hasil.get(SearchActivity.KEY_STAR))==5)
        {star.setImageResource(R.drawable.star5);}
    if(Integer.parseInt(hasil.get(SearchActivity.KEY_STAR))==4)
        {star.setImageResource(R.drawable.star4);}
    if(Integer.parseInt(hasil.get(SearchActivity.KEY_STAR))==3)
        {star.setImageResource(R.drawable.star3);}
    if(Integer.parseInt(hasil.get(SearchActivity.KEY_STAR))==2)
        {star.setImageResource(R.drawable.star2);}
    if(Integer.parseInt(hasil.get(SearchActivity.KEY_STAR))==1)
        {star.setImageResource(R.drawable.star1);}

    imageLoader.DisplayImg("http://www.jogjabagus.com/" + hasil.get(SearchActivity.KEY_THUMB_URL), thumb_image);
    return vi;
}

}

2 个答案:

答案 0 :(得分:0)

尝试此操作以从ArrayList

中删除重复项
public static ArrayList<Integer> removeDuplicates(ArrayList<Integer> list) {

    // Store unique items in result.
    ArrayList<Integer> result = new ArrayList<>();

    // Record encountered Strings in HashSet.
    HashSet<Integer> set = new HashSet<>();

    // Loop over argument list.
    for (Integer item : list) {

        // If String is not in set, add it to the list and the set.
        if (!set.contains(item)) {
            result.add(item);
            set.add(item);
        }
    }
    return result;
}

答案 1 :(得分:0)

  1. 将此列表转换为简单集合集并转换回列表,这样您将获得包含唯一值的列表。

  2. 对SQLite使用不同的查询。