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.androidhacks7.apprtc_android.RegistrationActivity.java

private void updateUI(final ArrayList<String> userNames) {
    ListView listView = (ListView) findViewById(R.id.userList);
    listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, userNames));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from w  w w . j av  a2  s.  c  o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Log.d(TAG, "Initiating call to " + userNames.get(i));
            Intent intent = new Intent(RegistrationActivity.this, VideoCallActivity.class);
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put(JSONConstants.CALLER, currentUser);
                jsonObject.put(JSONConstants.RECEIVER, userNames.get(i));
            } catch (JSONException e) {
                e.printStackTrace();
            }
            intent.putExtra(JSONConstants.MAKE_CALL, true);
            intent.putExtra(JSONConstants.CALL_PARAMS, jsonObject.toString());
            startActivity(intent);
            finish();
        }
    });
}

From source file:com.cloverstudio.spika.MyProfileActivity.java

private void Initialization() {

    if (SpikaApp.hasNetworkConnection()) {
        getLoginUserData();//from www  . j a  va 2s. c o m
    }

    mSvProfile = (ScrollView) findViewById(R.id.svProfile);
    mRlEditControls = (RelativeLayout) findViewById(R.id.rlEditControls);
    mRlBirthday = (RelativeLayout) findViewById(R.id.rlBirthday);
    mRlAbout = (RelativeLayout) findViewById(R.id.rlAbout);
    mRlGender = (RelativeLayout) findViewById(R.id.rlGender);
    mRlEmail = (RelativeLayout) findViewById(R.id.rlEmail);
    mRlOnlineStatus = (RelativeLayout) findViewById(R.id.rlOnlineStatus);
    mIvProfileImage = (ImageView) findViewById(R.id.ivProfileImage);
    mPbLoading = (ProgressBar) findViewById(R.id.pbLoadingForImage);
    mBtnEdit = (Button) findViewById(R.id.btnEdit);
    mBtnEdit.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
    mBtnSave = (Button) findViewById(R.id.btnSave);
    mBtnSave.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
    mTvUserName = (TextView) findViewById(R.id.tvUserName);
    mEtUserName = (EditText) findViewById(R.id.etUserName);
    mEtUserName.setTypeface(SpikaApp.getTfMyriadPro());
    mEtUserEmail = (EditText) findViewById(R.id.etUserEmail);
    mEtUserEmail.setTypeface(SpikaApp.getTfMyriadPro());
    mEtUserEmail.setInputType(InputType.TYPE_NULL);

    mSpinnerGender = (Spinner) findViewById(R.id.spinnerGender);
    final ArrayAdapter<String> genderAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.gender)) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            ((TextView) v).setTextSize(16);
            ((TextView) v).setTypeface(SpikaApp.getTfMyriadPro());
            if (position == 2) {
                ((TextView) v).setTextColor(getResources().getColor(R.color.light_gray_subtext));
                ((TextView) v).setText(getResources().getString(R.string.tap_to_add_gender));
            } else {
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
            }
            return v;
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            View v = super.getDropDownView(position, convertView, parent);
            ((TextView) v).setTextSize(20);
            ((TextView) v).setTypeface(SpikaApp.getTfMyriadPro());
            ((TextView) v).setPadding(15, 15, 15, 15);
            if (position == 2) {
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_neutral));
            } else {
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
            }
            return v;
        }
    };
    mSpinnerGender.setAdapter(genderAdapter);
    mSpinnerGender.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            switch (arg2) {
            case 0:
                mNewGender = Const.MALE;
                break;
            case 1:
                mNewGender = Const.FEMALE;
                break;
            case 2:
                mNewGender = null;
                break;
            default:
                break;
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

    mSpinnerStatus = (Spinner) findViewById(R.id.spinnerStatus);
    final ArrayAdapter<String> onlineStatusAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.online_status)) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            ((TextView) v).setTextSize(16);
            ((TextView) v).setTypeface(SpikaApp.getTfMyriadPro());

            Drawable statusIcon = null;

            switch (position) {
            case 0:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_online_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            case 1:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_away_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            case 2:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_busy_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            case 3:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_offline_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            default:
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            }

            ((TextView) v).setCompoundDrawablePadding(10);
            ((TextView) v).setCompoundDrawablesWithIntrinsicBounds(statusIcon, null, null, null);

            return v;
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            View v = super.getDropDownView(position, convertView, parent);
            ((TextView) v).setTextSize(20);
            ((TextView) v).setTypeface(SpikaApp.getTfMyriadPro());
            ((TextView) v).setPadding(15, 15, 15, 15);
            Drawable statusIcon = null;

            switch (position) {
            case 0:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_online_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            case 1:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_away_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            case 2:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_busy_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            case 3:
                statusIcon = getContext().getResources().getDrawable(R.drawable.user_offline_icon);
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            default:
                ((TextView) v).setTextColor(getResources().getColor(R.color.hookup_positive));
                break;
            }

            ((TextView) v).setCompoundDrawablePadding(10);
            ((TextView) v).setCompoundDrawablesWithIntrinsicBounds(statusIcon, null, null, null);
            return v;
        }
    };
    mSpinnerStatus.setAdapter(onlineStatusAdapter);
    mSpinnerStatus.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            switch (arg2) {
            case 0:
                mNewOnlineStatus = Const.ONLINE;
                break;
            case 1:
                mNewOnlineStatus = Const.AWAY;
                break;
            case 2:
                mNewOnlineStatus = Const.BUSY;
                break;
            case 3:
                mNewOnlineStatus = Const.OFFLINE;
                break;
            default:
                break;
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

    mEtUserPassword = (EditText) findViewById(R.id.etUserPassword);
    mEtUserPassword.setTypeface(SpikaApp.getTfMyriadPro());

    mEtUserAbout = (EditText) findViewById(R.id.etUserAbout);
    mEtUserAbout.setTypeface(SpikaApp.getTfMyriadPro());
    mEtUserBirthday = (EditText) findViewById(R.id.etUserBirthday);
    mEtUserBirthday.setTypeface(SpikaApp.getTfMyriadPro());

    setProfileMode(ProfileMode.CANCEL);

}

From source file:com.mifos.mifosxdroid.dialogfragments.chargedialog.ChargeDialogFragment.java

@Override
public void showAllChargesV2(ResponseBody result) {
    /* Activity is null - Fragment has been detached; no need to do anything. */
    if (getActivity() == null)
        return;//w  ww .j a v  a  2  s  .co  m

    Log.d(LOG_TAG, "Charges Loaded Successfully");

    final List<Charges> charges = new ArrayList<>();
    // you can use this array to populate your spinner
    final ArrayList<String> chargesNames = new ArrayList<String>();
    //Try to get response body
    BufferedReader reader = null;
    StringBuilder sb = new StringBuilder();
    try {
        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("chargeOptions")) {
            JSONArray chargesTypes = obj.getJSONArray("chargeOptions");
            for (int i = 0; i < chargesTypes.length(); i++) {
                JSONObject chargesObject = chargesTypes.getJSONObject(i);
                Charges charge = new Charges();
                charge.setId(chargesObject.optInt("id"));
                charge.setName(chargesObject.optString("name"));
                charges.add(charge);
                chargesNames.add(chargesObject.optString("name"));
                chargeNameIdHashMap.put(charge.getName(), charge.getId());
            }

        }
        String stringResult = sb.toString();
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage());
    }
    final ArrayAdapter<String> chargesAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, chargesNames);
    chargesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_charge_name.setAdapter(chargesAdapter);
    sp_charge_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            Id = chargeNameIdHashMap.get(chargesNames.get(i));
            Log.d("chargesoptionss" + chargesNames.get(i), String.valueOf(Id));
            if (Id != -1) {

            } else {

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

            }

        }

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

        }
    });

}

From source file:org.mifos.androidclient.templates.OperationFormActivity.java

public Spinner addComboBoxFormField(String fieldLabel, List<String> elements) {
    LinearLayout field = (LinearLayout) getLayoutInflater().inflate(R.layout.combo_box_form_field, null);
    TextView label = (TextView) field.findViewById(R.id.comboBoxFormField_label);
    label.setText(fieldLabel);/*from   www .  j a  v a2s  . c  o  m*/
    Spinner input = (Spinner) field.findViewById(R.id.comboBoxFormField_input);
    input.setPrompt(fieldLabel);
    input.setAdapter(new ArrayAdapter(this, R.layout.combo_box_item, elements));
    mFormFields.addView(field, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    return input;
}

From source file:com.irccloud.android.activity.LoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xff0b2e60));/*from   w ww  .ja  v  a2 s.  c  o  m*/
        cloud.recycle();
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    setContentView(R.layout.activity_login);

    loading = findViewById(R.id.loading);

    connecting = findViewById(R.id.connecting);
    connectingMsg = (TextView) findViewById(R.id.connectingMsg);
    progressBar = (ProgressBar) findViewById(R.id.connectingProgress);

    loginHint = (LinearLayout) findViewById(R.id.loginHint);
    signupHint = (LinearLayout) findViewById(R.id.signupHint);
    hostHint = (TextView) findViewById(R.id.hostHint);

    login = findViewById(R.id.login);
    name = (EditText) findViewById(R.id.name);
    if (savedInstanceState != null && savedInstanceState.containsKey("name"))
        name.setText(savedInstanceState.getString("name"));
    email = (AutoCompleteTextView) findViewById(R.id.email);
    if (BuildConfig.ENTERPRISE)
        email.setHint(R.string.email_enterprise);
    ArrayList<String> accounts = new ArrayList<String>();
    AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
    for (Account a : am.getAccounts()) {
        if (a.name.contains("@") && !accounts.contains(a.name))
            accounts.add(a.name);
    }
    if (accounts.size() > 0)
        email.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                accounts.toArray(new String[accounts.size()])));

    if (savedInstanceState != null && savedInstanceState.containsKey("email"))
        email.setText(savedInstanceState.getString("email"));

    password = (EditText) findViewById(R.id.password);
    password.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                new LoginTask().execute((Void) null);
                return true;
            }
            return false;
        }
    });
    if (savedInstanceState != null && savedInstanceState.containsKey("password"))
        password.setText(savedInstanceState.getString("password"));

    host = (EditText) findViewById(R.id.host);
    if (BuildConfig.ENTERPRISE)
        host.setText(NetworkConnection.IRCCLOUD_HOST);
    else
        host.setVisibility(View.GONE);
    host.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                new LoginTask().execute((Void) null);
                return true;
            }
            return false;
        }
    });
    if (savedInstanceState != null && savedInstanceState.containsKey("host"))
        host.setText(savedInstanceState.getString("host"));
    else
        host.setText(getSharedPreferences("prefs", 0).getString("host", BuildConfig.HOST));

    if (host.getText().toString().equals("api.irccloud.com")
            || host.getText().toString().equals("www.irccloud.com"))
        host.setText("");

    loginBtn = (Button) findViewById(R.id.loginBtn);
    loginBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new LoginTask().execute((Void) null);
        }
    });
    loginBtn.setFocusable(true);
    loginBtn.requestFocus();

    sendAccessLinkBtn = (Button) findViewById(R.id.sendAccessLink);
    sendAccessLinkBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            new ResetPasswordTask().execute((Void) null);
        }
    });

    nextBtn = (Button) findViewById(R.id.nextBtn);
    nextBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (host.getText().length() > 0) {
                NetworkConnection.IRCCLOUD_HOST = host.getText().toString();
                trimHost();

                new EnterpriseConfigTask().execute((Void) null);
            }
        }
    });

    TOS = (TextView) findViewById(R.id.TOS);
    TOS.setMovementMethod(new LinkMovementMethod());

    forgotPassword = (TextView) findViewById(R.id.forgotPassword);
    forgotPassword.setOnClickListener(forgotPasswordClickListener);

    enterpriseLearnMore = (TextView) findViewById(R.id.enterpriseLearnMore);
    enterpriseLearnMore.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (isPackageInstalled("com.irccloud.android", LoginActivity.this)) {
                startActivity(getPackageManager().getLaunchIntentForPackage("com.irccloud.android"));
            } else {
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=com.irccloud.android")));
                } catch (Exception e) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=com.irccloud.android")));
                }
            }
        }

        private boolean isPackageInstalled(String packagename, Context context) {
            PackageManager pm = context.getPackageManager();
            try {
                pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
                return true;
            } catch (NameNotFoundException e) {
                return false;
            }
        }
    });
    enterpriseHint = (LinearLayout) findViewById(R.id.enterpriseHint);

    EnterYourEmail = (TextView) findViewById(R.id.enterYourEmail);

    signupHint.setOnClickListener(signupHintClickListener);
    loginHint.setOnClickListener(loginHintClickListener);

    signupBtn = (Button) findViewById(R.id.signupBtn);
    signupBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            new LoginTask().execute((Void) null);
        }
    });

    TextView version = (TextView) findViewById(R.id.version);
    try {
        version.setText("Version " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
    } catch (NameNotFoundException e) {
        version.setVisibility(View.GONE);
    }

    Typeface LatoRegular = Typeface.createFromAsset(getAssets(), "Lato-Regular.ttf");
    Typeface LatoLightItalic = Typeface.createFromAsset(getAssets(), "Lato-LightItalic.ttf");

    for (int i = 0; i < signupHint.getChildCount(); i++) {
        View v = signupHint.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
        }
    }

    for (int i = 0; i < loginHint.getChildCount(); i++) {
        View v = loginHint.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
        }
    }

    LinearLayout IRCCloud = (LinearLayout) findViewById(R.id.IRCCloud);
    for (int i = 0; i < IRCCloud.getChildCount(); i++) {
        View v = IRCCloud.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
        }
    }

    notAProblem = (LinearLayout) findViewById(R.id.notAProblem);
    for (int i = 0; i < notAProblem.getChildCount(); i++) {
        View v = notAProblem.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface((i == 0) ? LatoRegular : LatoLightItalic);
        }
    }

    loginSignupHint = (LinearLayout) findViewById(R.id.loginSignupHint);
    for (int i = 0; i < loginSignupHint.getChildCount(); i++) {
        View v = loginSignupHint.getChildAt(i);
        if (v instanceof TextView) {
            ((TextView) v).setTypeface(LatoRegular);
            ((TextView) v).setOnClickListener((i == 0) ? loginHintClickListener : signupHintClickListener);
        }
    }

    name.setTypeface(LatoRegular);
    email.setTypeface(LatoRegular);
    password.setTypeface(LatoRegular);
    host.setTypeface(LatoRegular);
    loginBtn.setTypeface(LatoRegular);
    signupBtn.setTypeface(LatoRegular);
    TOS.setTypeface(LatoRegular);
    EnterYourEmail.setTypeface(LatoRegular);
    hostHint.setTypeface(LatoLightItalic);

    if (BuildConfig.ENTERPRISE) {
        name.setVisibility(View.GONE);
        email.setVisibility(View.GONE);
        password.setVisibility(View.GONE);
        loginBtn.setVisibility(View.GONE);
        signupBtn.setVisibility(View.GONE);
        TOS.setVisibility(View.GONE);
        signupHint.setVisibility(View.GONE);
        loginHint.setVisibility(View.GONE);
        forgotPassword.setVisibility(View.GONE);
        loginSignupHint.setVisibility(View.GONE);
        EnterYourEmail.setVisibility(View.GONE);
        sendAccessLinkBtn.setVisibility(View.GONE);
        notAProblem.setVisibility(View.GONE);
        enterpriseLearnMore.setVisibility(View.VISIBLE);
        enterpriseHint.setVisibility(View.VISIBLE);
        host.setVisibility(View.VISIBLE);
        nextBtn.setVisibility(View.VISIBLE);
        hostHint.setVisibility(View.VISIBLE);
        host.requestFocus();
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("signup")
            && savedInstanceState.getBoolean("signup")) {
        signupHintClickListener.onClick(null);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("login")
            && savedInstanceState.getBoolean("login")) {
        loginHintClickListener.onClick(null);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("forgotPassword")
            && savedInstanceState.getBoolean("forgotPassword")) {
        forgotPasswordClickListener.onClick(null);
    }

    mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean("resolving_error", false);

    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Auth.CREDENTIALS_API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
}

From source file:com.mifos.mifosxdroid.dialogfragments.loanchargedialog.LoanChargeDialogFragment.java

@Override
public void showAllChargesV3(ResponseBody result) {

    /* Activity is null - Fragment has been detached; no need to do anything. */
    if (getActivity() == null)
        return;/*from  ww  w.ja  va 2  s.  c om*/

    Log.d(LOG_TAG, "");

    final List<Charges> charges = new ArrayList<>();
    // you can use this array to populate your spinner
    final ArrayList<String> chargesNames = new ArrayList<String>();
    //Try to get response body
    BufferedReader reader = null;
    StringBuilder sb = new StringBuilder();
    try {
        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("chargeOptions")) {
            JSONArray chargesTypes = obj.getJSONArray("chargeOptions");
            for (int i = 0; i < chargesTypes.length(); i++) {
                JSONObject chargesObject = chargesTypes.getJSONObject(i);
                Charges charge = new Charges();
                charge.setId(chargesObject.optInt("id"));
                charge.setName(chargesObject.optString("name"));
                charges.add(charge);
                chargesNames.add(chargesObject.optString("name"));
                chargeNameIdHashMap.put(charge.getName(), charge.getId());
            }

        }
        String stringResult = sb.toString();
    } catch (Exception e) {
        Log.e(LOG_TAG, "", e);
    }
    final ArrayAdapter<String> chargesAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, chargesNames);
    chargesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_charge_name.setAdapter(chargesAdapter);
    sp_charge_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            Id = chargeNameIdHashMap.get(chargesNames.get(i));
            Log.d("chargesoptionss" + chargesNames.get(i), String.valueOf(Id));
            if (Id != -1) {

            } else {

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

            }

        }

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

        }
    });
}

From source file:com.mifos.mifosxdroid.dialogfragments.loanaccountdisbursement.LoanAccountDisbursement.java

@Override
public void showLoanTemplate(ResponseBody result) {

    final ArrayList<PaymentTypeOptions> paymentOption = new ArrayList<PaymentTypeOptions>();
    final ArrayList<String> paymentNames = new ArrayList<String>();
    BufferedReader reader = null;
    StringBuilder sb = new StringBuilder();
    String line;/*from www  .j  av a  2  s .c o m*/
    try {
        reader = new BufferedReader(new InputStreamReader(result.byteStream()));
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        JSONObject obj = new JSONObject(sb.toString());
        if (obj.has("paymentTypeOptions")) {
            JSONArray paymentOptions = obj.getJSONArray("paymentTypeOptions");
            for (int i = 0; i < paymentOptions.length(); i++) {
                JSONObject paymentObject = paymentOptions.getJSONObject(i);
                PaymentTypeOptions payment = new PaymentTypeOptions();
                payment.setId(paymentObject.optInt("id"));
                payment.setName(paymentObject.optString("name"));
                paymentOption.add(payment);
                paymentNames.add(paymentObject.optString("name"));
                paymentNameIdHashMap.put(payment.getName(), payment.getId());
            }
        }
        String stringResult = sb.toString();
    } catch (Exception e) {
        Log.e(LOG_TAG, "", e);
    }
    ArrayAdapter<String> paymentAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, paymentNames);
    paymentAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_payment_type.setAdapter(paymentAdapter);
    sp_payment_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            paymentTypeId = paymentNameIdHashMap.get(paymentNames.get(i));
            Log.d("paymentId " + paymentNames.get(i), String.valueOf(paymentTypeId));
            if (paymentTypeId != -1) {

            } else {

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

            }

        }

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

        }
    });
}

From source file:cc.softwarefactory.lokki.android.fragments.AddContactsFragment.java

private void setListAdapter() {

    adapter = new ArrayAdapter<String>(getActivity(), R.layout.add_people_row_layout, contactList) {

        @Override/* w w  w  .j  a v a2  s  . c  o m*/
        public View getView(final int position, View convertView, ViewGroup parent) {

            ViewHolder holder;

            if (convertView == null) {
                convertView = getActivity().getLayoutInflater().inflate(R.layout.add_people_row_layout, parent,
                        false);
                holder = new ViewHolder();
                holder.name = (TextView) convertView.findViewById(R.id.contact_name);
                holder.email = (TextView) convertView.findViewById(R.id.contact_email);
                holder.photo = (ImageView) convertView.findViewById(R.id.contact_photo);
                convertView.setTag(holder);

            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            try {
                AQuery aq = new AQuery(convertView);
                String contactName = getItem(position);
                final String email = MainApplication.mapping.getString(contactName);

                avatarLoader.load(email, holder.photo);

                aq.id(holder.name).text(contactName);
                aq.id(holder.email).text(email);
                holder.position = position;

                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final Context context = getContext();
                        String title = context.getResources().getString(R.string.add_contact);
                        String message = context.getResources().getString(R.string.add_contact_dialog_save,
                                email);
                        new AlertDialog.Builder(context).setTitle(title).setMessage(message)
                                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        try {
                                            ServerApi.allowPeople(context, email);
                                            contactList.remove(position);
                                            notifyDataSetChanged();
                                            Toast.makeText(context, R.string.contact_added, Toast.LENGTH_SHORT)
                                                    .show();
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }).setNegativeButton(R.string.cancel, null).show();
                    }
                });

            } catch (JSONException e) {
                Log.e(TAG, e.getMessage());
            }
            return convertView;
        }
    };

    aq.id(R.id.add_contacts_list_view).adapter(adapter);
}

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

private void setAdapterForState() {
    statesArrayList = SingleTon.getInstance().getSelectedStates();

    if (statesArrayList.size() > 0) {
        //gettingLicenceState=mProfileInfoModel.getDrivinglicensestate();
        gettingState = mProfileInfoModel.getStateID();
        int i = 0;
        for (State state : statesArrayList) {
            //String stateName=state.getStateName();
            String stateName = state.getStateId();

            //Log.e("stateID=", stateName);
            if (gettingState.equals(stateName)) {
                gettingStatePosition = i;
            }/* ww  w .j av  a  2s .c o  m*/
            i++;
        }
    }
    ArrayAdapter<State> dataAdapter = new ArrayAdapter<State>(this, R.layout.spinner_list, statesArrayList);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    stateSpinner.setAdapter(dataAdapter);
    stateSpinner.setSelection(gettingStatePosition);

}

From source file:org.mifos.androidclient.templates.OperationFormActivity.java

public void replaceComboBoxItems(Spinner comboBox, List<String> items) {
    comboBox.setAdapter(new ArrayAdapter(this, R.layout.combo_box_item, items));
}