Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

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

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:com.df.app.carCheck.VehicleInfoLayout.java

/**
 * edit/*  www  . ja v  a2 s.c  o m*/
 */
private void setManufacturerEdit(final Brand brand) {
    // adapterbrandmanufacturer??
    final ArrayAdapter<String> adapter;

    if (brand == null) {
        adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1,
                Helper.getEmptyStringList());
    } else {
        adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1,
                brand.getManufacturerNames());
    }

    final Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            if (message.what == 0) {
                manufacturerEdit.setText("");
                seriesEdit.setText("");
                modelEdit.setText("");
            } else {
                Manufacturer manufacturer = brand.manufacturers.get(message.what - 1);
                manufacturerEdit.setText(manufacturer.name);

                // ??edit
                if (lastManufacturerIndex != message.what) {
                    seriesEdit.setText("");
                    modelEdit.setText("");
                }

                setSeriesEdit(manufacturer);
            }

            lastManufacturerIndex = message.what;

            return true;
        }
    });

    // ????series
    if (brand.getManufacturerNames().size() == 2) {
        lastManufacturerIndex = 1;
        manufacturerEdit.setText(brand.getManufacturerNames().get(1));
        setSeriesEdit(brand.manufacturers.get(0));
        return;
    }
    // ?manufactuer
    else {
        showListDialog(R.string.chooseManufacturer, adapter, handler);
    }

    // manufacturerEdit
    manufacturerEdit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            showListDialog(R.string.chooseManufacturer, adapter, handler);
        }
    });
}

From source file:com.arantius.tivocommander.ShowList.java

public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    if (position > mShowData.size()) {
        return false;
    }/*w w w.  ja v  a  2 s .  c  om*/
    if (mShowStatus.get(position) != ShowStatus.LOADED) {
        return false;
    }

    mLongPressIndex = position;
    mLongPressItem = mShowData.get(position);
    if (mLongPressItem.has("recordingForChildRecordingId") && !mLongPressItem.has("folderType")) {
        mLongPressItem = mLongPressItem.path("recordingForChildRecordingId");
    }

    final Pair<ArrayList<String>, ArrayList<Integer>> choices = getLongPressChoices(mLongPressItem);
    if (choices == null) {
        return false;
    }
    final ArrayAdapter<String> choicesAdapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, choices.first);

    Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Operation?");
    dialogBuilder.setAdapter(choicesAdapter, this);
    AlertDialog dialog = dialogBuilder.create();
    dialog.show();

    return true;
}

From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java

private void inflatetransactionProcessingStrategySpinner(ResponseBody result) {

    final List<TransactionProcessingStrategy> transactionProcessingStrategyType = new ArrayList<>();
    // you can use this array to populate your spinner
    final ArrayList<String> transactionProcessingStrategyTypeNames = new ArrayList<String>();
    //Try to get response body
    BufferedReader reader = null;
    StringBuilder sb = new StringBuilder();
    try {/* w  ww. j  a v  a 2s  .c  om*/
        reader = new BufferedReader(new InputStreamReader(result.byteStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        JSONObject obj = new JSONObject(sb.toString());
        if (obj.has("transactionProcessingStrategyOptions")) {
            JSONArray transactionProcessingStrategyTypes = obj
                    .getJSONArray("transactionProcessingStrategyOptions");
            for (int i = 0; i < transactionProcessingStrategyTypes.length(); i++) {
                JSONObject transactionProcessingStrategyTypeObject = transactionProcessingStrategyTypes
                        .getJSONObject(i);
                TransactionProcessingStrategy transactionProcessingStrategy = new TransactionProcessingStrategy();
                transactionProcessingStrategy.setId(transactionProcessingStrategyTypeObject.optInt("id"));
                transactionProcessingStrategy
                        .setName(transactionProcessingStrategyTypeObject.optString("name"));
                transactionProcessingStrategyType.add(transactionProcessingStrategy);
                transactionProcessingStrategyTypeNames
                        .add(transactionProcessingStrategyTypeObject.optString("name"));
                transactionProcessingStrategyTypeIdHashMap.put(transactionProcessingStrategy.getName(),
                        transactionProcessingStrategy.getId());
            }

        }
        String stringResult = sb.toString();
    } catch (Exception e) {
        Log.e(LOG_TAG, "", e);
    }
    final ArrayAdapter<String> transactionProcessingStrategyAdapter = new ArrayAdapter<>(getActivity(),
            layout.simple_spinner_item, transactionProcessingStrategyTypeNames);

    transactionProcessingStrategyAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);

    sp_repaymentstrategy.setAdapter(transactionProcessingStrategyAdapter);
    sp_repaymentstrategy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            transactionProcessingStrategyId = transactionProcessingStrategyTypeIdHashMap
                    .get(transactionProcessingStrategyTypeNames.get(i));
            Log.d("transactionProcessing " + transactionProcessingStrategyTypeNames.get(i),
                    String.valueOf(transactionProcessingStrategyId));
            if (transactionProcessingStrategyId != -1) {

            } else {

                Toast.makeText(getActivity(), getString(R.string.error_select_transactionProcessingStrategy),
                        Toast.LENGTH_SHORT).show();

            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
}

From source file:com.mifos.mifosxdroid.online.GroupLoanAccountFragment.java

private void inflateLoanPurposeSpinner() {
    showProgress(true);/*from  ww  w  .  ja  v  a2 s  .  c o  m*/
    App.apiManager.getGroupLoansAccountTemplate(groupId, productId, new Callback<Response>() {
        @Override
        public void success(final Response result, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            Log.d(LOG_TAG, "");

            final List<LoanPurposeOptions> loanPurposeOptionsType = new ArrayList<>();
            // you can use this array to populate your spinner
            final ArrayList<String> loanPurposeOptionsTypeNames = new ArrayList<String>();
            //Try to get response body
            BufferedReader reader = null;
            StringBuilder sb = new StringBuilder();
            try {
                reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
                String line;
                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                }
                JSONObject obj = new JSONObject(sb.toString());
                if (obj.has("loanPurposeOptions")) {
                    JSONArray loanPurposeOptionsTypes = obj.getJSONArray("loanPurposeOptions");
                    for (int i = 0; i < loanPurposeOptionsTypes.length(); i++) {
                        JSONObject loanPurposeOptionsTypesObject = loanPurposeOptionsTypes.getJSONObject(i);
                        LoanPurposeOptions loanpurpose = new LoanPurposeOptions();
                        loanpurpose.setId(loanPurposeOptionsTypesObject.optInt("id"));
                        loanpurpose.setName(loanPurposeOptionsTypesObject.optString("name"));
                        loanPurposeOptionsType.add(loanpurpose);
                        loanPurposeOptionsTypeNames.add(loanPurposeOptionsTypesObject.optString("name"));
                        loanPurposeNameIdHashMap.put(loanpurpose.getName(), loanpurpose.getId());
                    }

                }
                String stringResult = sb.toString();
            } catch (Exception e) {
                Log.e(LOG_TAG, "", e);
            }
            final ArrayAdapter<String> loanPTypeAdapter = new ArrayAdapter<>(getActivity(),
                    layout.simple_spinner_item, loanPurposeOptionsTypeNames);

            loanPTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
            sp_loan_purpose.setAdapter(loanPTypeAdapter);
            sp_loan_purpose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    loanPurposeId = loanPurposeNameIdHashMap.get(loanPurposeOptionsTypeNames.get(i));
                    Log.d("loanpurpose" + loanPurposeOptionsTypeNames.get(i), String.valueOf(loanPurposeId));
                    if (loanPurposeId != -1) {

                    } else {

                        Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT)
                                .show();

                    }

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            showProgress(false);

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            Log.d(LOG_TAG, retrofitError.getLocalizedMessage());

            showProgress(false);
        }
    });
}

From source file:com.parking.billing.ParkingPayment.java

/**
 * Sets up the UI.//from   w  w  w  . ja  v a2 s  .com
 */
private void setupWidgets() {
    mBuyButton = (Button) findViewById(R.id.buy_button);
    mBuyButton.setEnabled(false);
    mBuyButton.setOnClickListener(this);

    mSelectLicensePlateSpinner = (Spinner) findViewById(R.id.license_plate_choices);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, AppPreferences.getInstance().getLicensePlateList());
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSelectLicensePlateSpinner.setAdapter(spinnerArrayAdapter);

    //mSelectItemSpinner = (Spinner) findViewById(R.id.item_choices);
    mCatalogAdapter = new CatalogAdapter(this, CATALOG);
    //mSelectItemSpinner.setAdapter(mCatalogAdapter);
    paymentCalculation();
    //mSelectItemSpinner.setOnItemSelectedListener(this);
}

From source file:com.zira.registration.VehicleInformationActivity.java

protected void setApapterForState() {

    ArrayAdapter<State> dataAdapter = new ArrayAdapter<State>(this, R.layout.spinner_list, stateList);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    StateNameSpinner.setAdapter(dataAdapter);
    if (value == 1) {
        //gettingStatePosition=0;
        //StateNameSpinner.setSelection(gettingStatePosition);
        if (stateList.size() > gettingStatePosition) {
            StateNameSpinner.setSelection(gettingStatePosition);
        }/*w  w  w.jav a 2 s.  c o m*/
        if (flag > 1) {
            StateNameSpinner.setSelection(gettingStatePosition);
        }
        //if((mProfileInfoModel.getLicenseplatecountryID()).equalsIgnoreCase())
    }
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * /*www .  ja v a  2s  .co m*/
 * @param arrayId
 * @param editViewId
 */
private void choose(final int arrayId, final int editViewId) {
    View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null);

    final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create();

    TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);

    final ListView listView = new ListView(view1.getContext());

    listView.setAdapter(new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1,
            view1.getResources().getStringArray(arrayId)));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            dialog.dismiss();
            String temp = (String) listView.getItemAtPosition(i);
            setEditViewText(rootView, editViewId, temp);
        }
    });

    contentArea.addView(listView);

    setTextView(view1, R.id.title, getResources().getString(R.string.alert));

    dialog.show();
}

From source file:de.lespace.apprtc.activity.ConnectActivity.java

@Override
public void onResume() {

    userList = new ArrayList<String>();
    String roomListJson = sharedPref.getString(keyprefRoomList, null);
    if (roomListJson != null) {
        try {/*w  ww. ja  va2s.c  o m*/
            JSONArray jsonArray = new JSONArray(roomListJson);
            for (int i = 0; i < jsonArray.length(); i++) {
                userList.add(jsonArray.get(i).toString());
            }
        } catch (JSONException e) {
            Log.e(TAG, "Failed to load room list: " + e.toString());
        }
    }
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, userList);
    roomListView.setAdapter(adapter);
    if (adapter.getCount() > 0) {
        roomListView.requestFocus();
        roomListView.setItemChecked(0, true);
    }

    super.onResume();
}

From source file:com.sakisds.icymonitor.activities.AddNotificationActivity.java

private void setAdapter(Spinner spinner, Sensor[] source) {
    String[] items = new String[source.length];
    for (int i = 0; i < items.length; i++) {
        items[i] = source[i].getName();//from  w w w.  j  av a  2  s.  c om
    }

    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, items);
    spinner.setAdapter(adapter);
}

From source file:com.sssemil.sonyirremote.ir.ir.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        setContentView(R.layout.settings_ir);
        main = false;//from w ww  .jav  a2s . c  o m

        final GetAwItems getAwItems1 = new GetAwItems(ir.this);
        String ret = getAwItems1.execute().get();

        spinner6 = ((Spinner) findViewById(R.id.spinner6));
        spinner6.setSelection(0);

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
                ar);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner6.setAdapter(dataAdapter);

        prepItemBrandArray();

        return true;
    } else if (id == R.id.action_about) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.about));
        PackageInfo pInfo = null;
        String version = "?";
        try {
            pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        version = pInfo.versionName;
        builder.setMessage(getResources().getString(R.string.license1) + " v" + version + "\n"
                + getResources().getString(R.string.license2) + "\n"
                + getResources().getString(R.string.license3) + "\n"
                + getResources().getString(R.string.license4));
        builder.setPositiveButton("OK", null);
        AlertDialog dialog = builder.show();

        TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        messageView.setGravity(Gravity.CENTER);
        return true;
    } else if (id == R.id.action_exit) {
        stopIR();
        System.exit(0);
        return true;
    } else if (id == R.id.action_update) {
        update();
        return true;
    }
    return super.onOptionsItemSelected(item);
}