Example usage for android.widget SimpleAdapter SimpleAdapter

List of usage examples for android.widget SimpleAdapter SimpleAdapter

Introduction

In this page you can find the example usage for android.widget SimpleAdapter SimpleAdapter.

Prototype

public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, @LayoutRes int resource,
        String[] from, @IdRes int[] to) 

Source Link

Document

Constructor

Usage

From source file:smart.services.adapter.ManageCarsAdapter.java

public void showInsuranceDialog() {
    dialog.setContentView(R.layout.add_car_dialog);
    dialog.setCancelable(true);//w  w w.  j av a  2 s .c om
    dialog.setTitle("Choose an Insurance company");
    Booking.changeWidthHeight(context, dialog);
    // dialog.setP
    lv = (ListView) dialog.findViewById(R.id.addLV);

    if (dataBaseHandler.getInsuranceCount() == 0) {
        if (isConnectingToInternet()) {
            new InsuranceCompany().execute();
        } else {
            Toast.makeText(context, "Check your internet connection", Toast.LENGTH_LONG).show();
        }
    } else {

        ArrayList<Insurance> insurances = dataBaseHandler.getAllInsurance();
        insuracneCompanyList.clear();

        for (int i = 0; i < insurances.size(); i++) {
            HashMap<String, String> insurance = new HashMap<String, String>();
            insurance.put("id", insurances.get(i).getId() + "");
            insurance.put("nameAr", insurances.get(i).getNameAr());
            insurance.put("nameEn", insurances.get(i).getNameEn());

            insuracneCompanyList.add(insurance);
        }
        ListAdapter adapter = new SimpleAdapter(context, insuracneCompanyList, R.layout.single_insurance_item,
                new String[] { "id", "nameEn" }, new int[] { R.id.insuranceId, R.id.nameEn });

        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                finalInsuranceId = insuracneCompanyList.get(position).get("id");

                String idC = ((TextView) view.findViewById(R.id.insuranceId)).getText().toString();
                insuranceIdTV.setText(idC);
                insuranceTV
                        .setText(dataBaseHandler.getInsurance(Integer.parseInt(finalInsuranceId)).getNameEn());
                dialog.dismiss();
            }
        });
        dialog.show();
    }
}

From source file:smart.services.fragment.AddCar.java

@SuppressLint("InlinedApi")
@SuppressWarnings("deprecation")
public void showColorDialog() {
    dialog.setContentView(R.layout.add_car_dialog);
    dialog.setCancelable(true);/*from  w  ww. j av  a 2s . c o  m*/

    TextView dialogTitleTV = (TextView) dialog.findViewById(R.id.brandsListTitleTV);

    Booking.changeWidthHeight(getActivity(), dialog);
    // dialog.setP
    lv = (ListView) dialog.findViewById(R.id.addLV);

    if (dataBaseHandler.getColorsCount() == 0) {
        if (carFunctions.isConnectingToInternet()) {
            new CarColor().execute();
        } else {
            Toast.makeText(getActivity(), "Check your internet connection", Toast.LENGTH_LONG).show();
        }
    } else {

        List<Color> colorList = dataBaseHandler.getAllColors();

        carsColorList.clear();
        for (int i = 0; i < colorList.size(); i++) {
            HashMap<String, String> color = new HashMap<String, String>();
            color.put("id", colorList.get(i).getColorId());
            color.put("coloAr", colorList.get(i).getColorAr());
            color.put("colorEn", colorList.get(i).getColorEn());

            carsColorList.add(color);
        }
        ListAdapter adapter = null;

        if (setting.getDuration() == 0) {
            dialog.findViewById(R.id.titleIVAr).setVisibility(View.GONE);
            dialogTitleTV.setText(getResources().getString(R.string.color_list_en));

            adapter = new SimpleAdapter(getActivity(), carsColorList, R.layout.single_color_item,
                    new String[] { "id", "colorEn" }, new int[] { R.id.id, R.id.colorEn });
        } else {
            dialog.findViewById(R.id.titleIVEn).setVisibility(View.GONE);
            dialogTitleTV.setText(getResources().getString(R.string.color_list_ar));

            adapter = new SimpleAdapter(getActivity(), carsColorList, R.layout.single_color_item,
                    new String[] { "id", "coloAr" }, new int[] { R.id.id, R.id.colorEn });
        }

        lv.setAdapter(adapter);

        swipeView = (SwipeRefreshLayout) dialog.findViewById(R.id.swipeDialog);
        swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeView.setRefreshing(true);
                if (carFunctions.isConnectingToInternet()) {
                    new CarColor().execute();
                } else {
                    Toast.makeText(getActivity(), "Check your internet connection", Toast.LENGTH_LONG).show();
                }
                swipeView.setRefreshing(false);
            }
        });
        swipeView.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
                android.R.color.holo_orange_light, android.R.color.holo_red_light);
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String colorEn = ((TextView) view.findViewById(R.id.colorEn)).getText().toString();
                String idC = ((TextView) view.findViewById(R.id.id)).getText().toString();
                colorNameTV.setText(colorEn);
                colorIdTV.setText(idC);
                dialog.dismiss();
            }
        });

        dialog.show();
    }
}

From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java

public void dropdownLTY() throws JSONException {
    RequestParams params = null;// w w w  . j  av  a 2s .  c  o m
    params = new RequestParams();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("TableName", "OCRD");
    jsonObject.put("FieldName", "LOAN_PRNCP_TYPE");
    params.put("sJsonInput", jsonObject.toString());

    RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("Failed");

        }

        @Override
        protected String parseResponse(String s, boolean b) throws Throwable {
            return null;
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Title Dropdown Success Details ");
            System.out.println(arg2);

            try {

                arrayResponse = new JSONArray(arg2);
                // Create new list
                jsonArraylist = new ArrayList<HashMap<String, String>>();

                for (int i = 0; i < arrayResponse.length(); i++) {

                    jsonResponse = arrayResponse.getJSONObject(i);

                    id = jsonResponse.getString("Id").toString();
                    name = jsonResponse.getString("Name").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> proList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON  LIST");
                    proList.put("Id_T", id);
                    System.out.println(name);
                    proList.put("Name_T", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON PROPERTY LIST");

                    jsonArraylist.add(proList);
                    System.out.println("JSON PROPERTY LIST");
                    System.out.println(jsonArraylist);
                }
                // Spinner set Array Data in Drop down

                sAdapPROJ = new SimpleAdapter(ProcessCaseLoanPrincipal.this, jsonArraylist,
                        R.layout.spinner_item, new String[] { "Id_T", "Name_T" },
                        new int[] { R.id.Id, R.id.Name });

                spinner_LoanTypeOfLoans.setAdapter(sAdapPROJ);

                for (int j = 0; j < jsonArraylist.size(); j++) {
                    if (jsonArraylist.get(j).get("Id_T").equals(SLoanTypeOfLoans)) {
                        spinner_LoanTypeOfLoans.setSelection(j);
                        break;
                    }
                }

            } catch (JSONException e) {

                e.printStackTrace();
            }
        }
    });
}

From source file:cm.aptoide.pt.ManageRepos.java

private void initReposList() {
    reposListAdapter = new SimpleAdapter(this, repos.getList(), R.layout.row_repo,
            new String[] { Constants.KEY_REPO_HASHID, Constants.KEY_REPO_URI, Constants.KEY_REPO_IN_USE,
                    Constants.KEY_REPO_SIZE },
            new int[] { R.id.repo_hashid, R.id.uri, R.id.in_use, R.id.size });
    reposListAdapter.setViewBinder(new ReposListBinder());
    setListAdapter(reposListAdapter);//from w w w .j a  v a 2  s.c  o m
}

From source file:com.abeo.tia.noordin.ProcesscaseLoanSubsidiary.java

public void dropdownf5() throws JSONException {
    RequestParams params = null;//from   w  w w. j av a  2 s .com
    params = new RequestParams();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("TableName", "OCRD");
    jsonObject.put("FieldName", "LOAN_PRNCP_TYPE");
    params.put("sJsonInput", jsonObject.toString());

    RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("Failed");

        }

        @Override
        protected String parseResponse(String s, boolean b) throws Throwable {
            return null;
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Title Dropdown Success Details ");
            System.out.println(arg2);

            try {

                arrayResponse = new JSONArray(arg2);
                // Create new list
                jsonArraylist = new ArrayList<HashMap<String, String>>();

                for (int i = 0; i < arrayResponse.length(); i++) {

                    jsonResponse = arrayResponse.getJSONObject(i);

                    id = jsonResponse.getString("Id").toString();
                    name = jsonResponse.getString("Name").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> proList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON  LIST");
                    proList.put("Id_T", id);
                    System.out.println(name);
                    proList.put("Name_T", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON PROPERTY LIST");

                    jsonArraylist.add(proList);
                    System.out.println("JSON PROPERTY LIST");
                    System.out.println(jsonArraylist);
                }
                // Spinner set Array Data in Drop down

                sAdapPROJ = new SimpleAdapter(ProcesscaseLoanSubsidiary.this, jsonArraylist,
                        R.layout.spinner_item, new String[] { "Id_T", "Name_T" },
                        new int[] { R.id.Id, R.id.Name });

                sf5.setAdapter(sAdapPROJ);

                /*for (int j = 0; j < jsonlistProject.size(); j++) {
                        if (jsonlistProject.get(j).get("Id_T").equals(projectDetailResponse)) {
                      TitleType_DROPDOWN.setSelection(j);
                      break;
                   }
                }*/

            } catch (JSONException e) {

                e.printStackTrace();
            }
        }
    });
}

From source file:com.abc.driver.MainActivity.java

public void chooseCargoType(View v) {
    mCTtv = (TextView) this.findViewById(R.id.cargo_type_tv);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);/*  w w  w.  j  a  v  a2 s .  c om*/
    // (GridView)findViewById(R.id.gridView1);
    SimpleAdapter adapter = new SimpleAdapter(this, mCargoTypeList, R.layout.cargo_type_griditem,
            new String[] { "PIC", "TITLE", "CTYPE" },
            new int[] { R.id.griditem_pic, R.id.griditem_title, R.id.griditem_type, });

    gridView1.setAdapter(adapter);
    builder.setTitle("Please Choose");
    builder.setInverseBackgroundForced(true);
    builder.setView(gridView1);
    final Dialog dialog = builder.create();

    gridView1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            // doing something in here and then close
            mCTtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText());
            mCargoType = ((TextView) view.findViewById(R.id.griditem_type)).getText().toString();
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:com.abc.driver.MainActivity.java

public void chooseTruckType(View v) {
    mTTtv = (TextView) this.findViewById(R.id.truck_type_tv);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);//  w  ww .j  a v  a 2  s . c om
    // (GridView)findViewById(R.id.gridView1);
    SimpleAdapter adapter = new SimpleAdapter(this, mTruckTypeList, R.layout.truck_type_griditem,
            new String[] { "PIC", "TITLE", "TTYPE" },
            new int[] { R.id.griditem_pic, R.id.griditem_title, R.id.griditem_type, });

    gridView1.setAdapter(adapter);
    builder.setTitle("Please Choose");
    builder.setInverseBackgroundForced(true);
    builder.setView(gridView1);
    final Dialog dialog = builder.create();

    gridView1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            mTTtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText());
            mTruckType = ((TextView) view.findViewById(R.id.griditem_type)).getText().toString();
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java

public void dropdownKIV() throws JSONException {
    RequestParams params = null;//from  ww w . j  av  a2 s .c o m
    params = new RequestParams();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("TableName", "OCRD");
    jsonObject.put("FieldName", "KIVSTATUS");
    params.put("sJsonInput", jsonObject.toString());

    RestService.post(GET_SPINNER_VALUES, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("Failed");

        }

        @Override
        protected String parseResponse(String s, boolean b) throws Throwable {
            return null;
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Title Dropdown Success Details ");
            System.out.println(arg2);

            try {

                arrayResponse = new JSONArray(arg2);
                // Create new list
                jsonArraylist = new ArrayList<HashMap<String, String>>();

                for (int i = 0; i < arrayResponse.length(); i++) {

                    jsonResponse = arrayResponse.getJSONObject(i);

                    id = jsonResponse.getString("Id").toString();
                    name = jsonResponse.getString("Name").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> proList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON  LIST");
                    proList.put("Id_T", id);
                    System.out.println(name);
                    proList.put("Name_T", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON PROPERTY LIST");

                    jsonArraylist.add(proList);
                    System.out.println("JSON PROPERTY LIST");
                    System.out.println(jsonArraylist);
                }
                // Spinner set Array Data in Drop down

                sAdapPROJ = new SimpleAdapter(ProcessCaseLoanPrincipal.this, jsonArraylist,
                        R.layout.spinner_item, new String[] { "Id_T", "Name_T" },
                        new int[] { R.id.Id, R.id.Name });

                spinner_kiv.setAdapter(sAdapPROJ);

                for (int j = 0; j < jsonArraylist.size(); j++) {
                    if (jsonArraylist.get(j).get("Id_T").equals(Skiv)) {
                        spinner_kiv.setSelection(j);
                        break;
                    }
                }

            } catch (JSONException e) {

                e.printStackTrace();
            }
        }
    });
}

From source file:com.abc.driver.MainActivity.java

public void chooseTruckLength(View v) {
    mTLtv = (TextView) findViewById(R.id.truck_length_tv);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);// w  w w  . j  a  v  a 2  s.com
    // (GridView)findViewById(R.id.gridView1);
    SimpleAdapter adapter = new SimpleAdapter(this, mTruckLengthList, R.layout.truck_length_griditem,
            new String[] { "TITLE", "TLENGTH" }, new int[] { R.id.griditem_title, R.id.griditem_length, });

    gridView1.setAdapter(adapter);
    builder.setTitle("Please Choose");
    builder.setInverseBackgroundForced(true);
    builder.setView(gridView1);
    final Dialog dialog = builder.create();

    gridView1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            mTLtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText());
            mTruckLength = ((TextView) view.findViewById(R.id.griditem_length)).getText().toString();
            dialog.dismiss();
        }
    });
    // */

    dialog.show();

}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

public void dropdownTitle() throws JSONException {

    RequestParams params = null;/*from   ww w. j  a  va 2s.c om*/
    params = new RequestParams();

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("TableName", "@AE_PROPERTY");
    jsonObject.put("FieldName", "TITLETYPE");
    params.put("sJsonInput", jsonObject.toString());

    RestService.post(TitleType_DROPDOWN, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("Failed");

        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("property Dropdown Success Details ");
            System.out.println(arg2);

            try {

                arrayResponse = new JSONArray(arg2);
                // Create new list
                jsonlistProject = new ArrayList<HashMap<String, String>>();

                for (int i = 0; i < arrayResponse.length(); i++) {

                    jsonResponse = arrayResponse.getJSONObject(i);

                    id = jsonResponse.getString("Id").toString();
                    name = jsonResponse.getString("Name").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> proList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND JSON  LIST");
                    proList.put("Id_T", id);
                    System.out.println(name);
                    proList.put("Name_T", name);
                    System.out.println(name);
                    System.out.println(" END SEND JSON PROPERTY LIST");

                    jsonlistProject.add(proList);
                    System.out.println("JSON PROPERTY LIST");
                    System.out.println(jsonlistProject);
                }
                // Spinner set Array Data in Drop down

                sAdapPROJ = new SimpleAdapter(AddCaseStep2of4.this, jsonlistProject, R.layout.spinner_item,
                        new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name });

                spinnerpropertyTitleType.setAdapter(sAdapPROJ);

                /*for (int j = 0; j < jsonlistProject.size(); j++) {
                   if (jsonlistProject.get(j).get("Id_T").equals(projectDetailResponse)) {
                      TitleType_DROPDOWN.setSelection(j);
                      break;
                   }
                }*/

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

        }

        @Override
        protected String parseResponse(String arg0, boolean arg1) throws Throwable {

            // Get Json response
            arrayResponse = new JSONArray(arg0);
            jsonResponse = arrayResponse.getJSONObject(0);

            System.out.println("Property Dropdown Details parse Response");
            System.out.println(arg0);
            return null;
        }
    });

}