Java Code Examples for android.widget.ArrayAdapter.getPosition()

The following are Jave code examples for showing how to use getPosition() of the android.widget.ArrayAdapter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: tuxguitar   File: TGBrowserView.java   Source Code and License Vote up 6 votes
@SuppressWarnings("unchecked")
public void refreshCollections() {
	ArrayAdapter<TGSelectableItem> arrayAdapter = new ArrayAdapter<TGSelectableItem>(findActivity(), R.layout.view_browser_spinner_item, createCollectionValues());
	arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	
	TGSelectableItem selectedItem = new TGSelectableItem(findCurrentCollection(), null);
	Integer selectedItemPosition = arrayAdapter.getPosition(selectedItem);
	
	Spinner spinner = (Spinner) this.findViewById(R.id.browser_collections);
	OnItemSelectedListener listener = spinner.getOnItemSelectedListener();
	spinner.setOnItemSelectedListener(null);
	if(!this.isSameCollection(arrayAdapter, (ArrayAdapter<TGSelectableItem>) spinner.getAdapter())) {
		spinner.setAdapter(arrayAdapter);
	}
	if( spinner.getSelectedItemPosition() != selectedItemPosition ) {
		spinner.setSelection(selectedItemPosition, false);
	}
	spinner.setOnItemSelectedListener(listener);
}
 
Example 2
Project: SOS-The-Healthcare-Companion   File: HelloActivity.java   Source Code and License Vote up 5 votes
public void setSpinner(String value, LabelledSpinner spinner) {
    if (!value.equals("-1")) {
        ArrayAdapter<CharSequence> adapter = (ArrayAdapter) spinner.getSpinner().getAdapter();
        int spinnerPosition = adapter.getPosition(value);
        spinner.setSelection(spinnerPosition);
    }
}
 
Example 3
Project: XERUNG   File: ProfileSetting.java   Source Code and License Vote up 5 votes
private void setBloodAdapter() {
    final String[] choices = {"A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"};
    ArrayAdapter<String> badapter = new ArrayAdapter<String>(ProfileSetting.this, android.R.layout.simple_spinner_item, choices);
    badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBloodGroup.setAdapter(badapter);
    try {
        if (!bloodGroup.equals(null) && !bloodGroup.equals("0")) {
            int spinnerPosition = badapter.getPosition(bloodGroup);
            spBloodGroup.setSelection(spinnerPosition + 1);
        }
    } catch (Exception e) {
        // TODO: handle exception
    }
}
 
Example 4
Project: XERUNG   File: ProfileSetting.java   Source Code and License Vote up 5 votes
private void setBloodAdapter() {
    final String[] choices = {"A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"};
    ArrayAdapter<String> badapter = new ArrayAdapter<String>(ProfileSetting.this, android.R.layout.simple_spinner_item, choices);
    badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBloodGroup.setAdapter(badapter);
    try {
        if (!bloodGroup.equals(null) && !bloodGroup.equals("0")) {
            int spinnerPosition = badapter.getPosition(bloodGroup);
            spBloodGroup.setSelection(spinnerPosition + 1);
        }
    } catch (Exception e) {
        // TODO: handle exception
    }
}
 
Example 5
Project: planetcon   File: StartActivity.java   Source Code and License Vote up 5 votes
private void loadPref(SharedPreferences prefs, Spinner spinner, int id, String key, String def) {
    // temporary adapter created to get the position of an item inside the array of values
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, id, android.R.layout.simple_spinner_item);
    String selectedString = prefs.getString(key, def);
    int position = adapter.getPosition(selectedString);
    // Force the spinner to load the stored preference
    spinner.setSelection(position);
}
 
Example 6
Project: planetcon   File: ListPlayersAdapter.java   Source Code and License Vote up 4 votes
private void loadPrefValue(CatchingSpinner spinner, int id, String item) {
    //Get the position of an item inside the array of values (resource id), and set as selected in the spinner
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, id, android.R.layout.simple_spinner_item);
    int position = adapter.getPosition(item);
    spinner.setSelection(position);
}
 
Example 7
Project: easyfilemanager   File: CreateConnectionFragment.java   Source Code and License Vote up 4 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = getActivity().getLayoutInflater();

    final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false);
    name = (AppCompatEditText) view.findViewById(R.id.name);
    host = (AppCompatEditText) view.findViewById(R.id.host);
    port = (AppCompatEditText) view.findViewById(R.id.port);
    path = (AppCompatEditText) view.findViewById(R.id.path);
    hostContainer = view.findViewById(R.id.hostContainer);
    pathContainer = view.findViewById(R.id.pathContainer);
    username = (AppCompatEditText) view.findViewById(R.id.username);
    usernameContainer = view.findViewById(R.id.usernameContainer);
    password = (AppCompatEditText) view.findViewById(R.id.password);
    passwordContainer = view.findViewById(R.id.passwordContainer);
    scheme = (AppCompatSpinner) view.findViewById(R.id.scheme);
    anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous);
    anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE);
            passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE);
        }
    });

    if(connection_id != 0){
        NetworkConnection connection =
                NetworkConnection.fromConnectionId(getActivity(), connection_id);

        ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter();
        int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase());
        scheme.setSelection(spinnerPosition);

        name.setText(connection.getName());
        host.setText(connection.getHost());
        port.setText(Integer.toString(connection.getPort()));
        path.setText(connection.getPath());
        username.setText(connection.getUserName());
        password.setText(connection.getPassword());
        anonymous.setChecked(connection.isAnonymousLogin());
        if(SERVER.equals(connection.getType())){
            hostContainer.setVisibility(View.GONE);
            pathContainer.setVisibility(View.VISIBLE);
        }
    }
    builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection");
    builder.setView(view);

    builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final BaseActivity activity = (BaseActivity) getActivity();

            NetworkConnection networkConnection = getNetworkConnection();
            if(validate(networkConnection)){
                new CreateConnectionTask(activity, networkConnection).executeOnExecutor(
                        ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY));
            }

        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    return builder.create();
}
 
Example 8
Project: FireFiles   File: CreateConnectionFragment.java   Source Code and License Vote up 4 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = getActivity().getLayoutInflater();

    final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false);
    name = (AppCompatEditText) view.findViewById(R.id.name);
    host = (AppCompatEditText) view.findViewById(R.id.host);
    port = (AppCompatEditText) view.findViewById(R.id.port);
    path = (AppCompatEditText) view.findViewById(R.id.path);
    hostContainer = view.findViewById(R.id.hostContainer);
    pathContainer = view.findViewById(R.id.pathContainer);
    username = (AppCompatEditText) view.findViewById(R.id.username);
    usernameContainer = view.findViewById(R.id.usernameContainer);
    password = (AppCompatEditText) view.findViewById(R.id.password);
    passwordContainer = view.findViewById(R.id.passwordContainer);
    scheme = (AppCompatSpinner) view.findViewById(R.id.scheme);
    anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous);
    anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE);
            passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE);
        }
    });

    if(connection_id != 0){
        NetworkConnection connection =
                NetworkConnection.fromConnectionId(getActivity(), connection_id);

        ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter();
        int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase());
        scheme.setSelection(spinnerPosition);

        name.setText(connection.getName());
        host.setText(connection.getHost());
        port.setText(Integer.toString(connection.getPort()));
        path.setText(connection.getPath());
        username.setText(connection.getUserName());
        password.setText(connection.getPassword());
        anonymous.setChecked(connection.isAnonymousLogin());
        if(SERVER.equals(connection.getType())){
            hostContainer.setVisibility(View.GONE);
            pathContainer.setVisibility(View.VISIBLE);
        }
    }
    builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection");
    builder.setView(view);

    builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final BaseActivity activity = (BaseActivity) getActivity();

            NetworkConnection networkConnection = getNetworkConnection();
            if(validate(networkConnection)){
                new CreateConnectionTask(activity, networkConnection).executeOnExecutor(
                        ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY));
            }

        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    return builder.create();
}
 
Example 9
Project: linkedout_procon   File: StudentModSettings.java   Source Code and License Vote up 4 votes
private void fillInData(SharedPreferences prefs) {
    //Edittext's connected to the fields in the student profile.
    EditText fullName = (EditText) findViewById(R.id.studentNameSettings);
    EditText email = (EditText) findViewById(R.id.studentEmailSettings);
    EditText major = (EditText) findViewById(R.id.studentMajorSettings);
    EditText city = (EditText) findViewById(R.id.studentCitySettings);
    EditText gradYear = (EditText) findViewById(R.id.studentGradYearSettings);
    EditText un = (EditText) findViewById(R.id.studentUsernameSettings);
    EditText pw = (EditText) findViewById(R.id.studentPasswordSettings);

    //Spinners for displaying states, and terms of graduation.
    Spinner stateSpinner = (Spinner) findViewById(R.id.stateSpinnerSettings);
    Spinner gradTermSpinner = (Spinner) findViewById(R.id.FallSpringSpinnerSettings);
    ArrayAdapter stateAdapter = (ArrayAdapter) stateSpinner.getAdapter();
    ArrayAdapter gradTermAdapter = (ArrayAdapter) gradTermSpinner.getAdapter();
    int statePos = stateAdapter.getPosition(prefs.getString("state","") );
    int gradPos = gradTermAdapter.getPosition(prefs.getString("gradTerm","") );

    //Getting data from the shared preferences to populate the student profile fields.
    fullName.setText(prefs.getString("fullName", ""));
    email.setText(prefs.getString("email",""));
    major.setText(prefs.getString("major",""));
    city.setText(prefs.getString("city",""));
    gradYear.setText(prefs.getString("gradYear",""));
    un.setText(prefs.getString("username",""));
    pw.setText(prefs.getString("password",""));
    stateSpinner.setSelection(statePos);
    gradTermSpinner.setSelection(gradPos);

    //Create new profile pic object.
    pic = new ProfilePic(null);
    ImageView profilePic = (ImageView) findViewById(R.id.thumbnailSettings);
    String imgString = prefs.getString("profilePic", "");
    //If the image string is blank, set the profile pic in the layout to the default
    //camera drawable image.
    if(imgString == "")
        profilePic.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_camera));
    //Otherwise, decode the image string, and use that bitmap for the profile pic.
    else {
        pic.setBitmap(pic.getDecodedBitmap(imgString));
        profilePic.setImageBitmap(pic.getResizedBitmap());
    }
}
 
Example 10
Project: simple-share-android   File: CreateConnectionFragment.java   Source Code and License Vote up 4 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = getActivity().getLayoutInflater();

    final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false);
    name = (AppCompatEditText) view.findViewById(R.id.name);
    host = (AppCompatEditText) view.findViewById(R.id.host);
    port = (AppCompatEditText) view.findViewById(R.id.port);
    path = (AppCompatEditText) view.findViewById(R.id.path);
    hostContainer = view.findViewById(R.id.hostContainer);
    pathContainer = view.findViewById(R.id.pathContainer);
    username = (AppCompatEditText) view.findViewById(R.id.username);
    usernameContainer = view.findViewById(R.id.usernameContainer);
    password = (AppCompatEditText) view.findViewById(R.id.password);
    passwordContainer = view.findViewById(R.id.passwordContainer);
    scheme = (AppCompatSpinner) view.findViewById(R.id.scheme);
    anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous);
    anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE);
            passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE);
        }
    });

    if(connection_id != 0){
        NetworkConnection connection =
                NetworkConnection.fromConnectionId(getActivity(), connection_id);

        ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter();
        int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase());
        scheme.setSelection(spinnerPosition);

        name.setText(connection.getName());
        host.setText(connection.getHost());
        port.setText(Integer.toString(connection.getPort()));
        path.setText(connection.getPath());
        username.setText(connection.getUserName());
        password.setText(connection.getPassword());
        anonymous.setChecked(connection.isAnonymousLogin());
        if(SERVER.equals(connection.getType())){
            hostContainer.setVisibility(View.GONE);
            pathContainer.setVisibility(View.VISIBLE);
        }
    }
    builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection");
    builder.setView(view);

    builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final BaseActivity activity = (BaseActivity) getActivity();

            NetworkConnection networkConnection = getNetworkConnection();
            if(validate(networkConnection)){
                new CreateConnectionTask(activity, networkConnection).executeOnExecutor(
                        ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY));
            }

        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    return builder.create();
}