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:org.kepennar.android.client.social.facebook.FacebookActivity.java

private void showFacebookOptions() {
    String[] options = { "Disconnect", "Profile", "Home Feed", "Wall Post" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);/*from  w  ww. j a v  a  2s. c  o m*/
    ListView listView = (ListView) this.findViewById(R.id.facebook_activity_options_list);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            Intent intent;
            switch (position) {
            case 0:
                disconnect();
                showConnectOption();
                break;
            case 1:
                intent = new Intent();
                intent.setClass(parentView.getContext(), FacebookProfileActivity.class);
                startActivity(intent);
                break;
            case 2:
                intent = new Intent();
                intent.setClass(parentView.getContext(), FacebookHomeFeedActivity.class);
                startActivity(intent);
                break;
            case 3:
                intent = new Intent();
                intent.setClass(parentView.getContext(), FacebookWallPostActivity.class);
                startActivity(intent);
                break;
            default:
                break;
            }
        }
    });
}

From source file:com.heneryh.aquanotes.ui.controllers.OutletsDataAdapter.java

public OutletsDataAdapter(Activity activity) {
    super(activity, null);
    mActivity = activity;/*  w  ww. ja  va 2  s.  c o m*/
    mHasAllItem = false;
    mPositionDisplacement = 0;
    Resources res = mActivity.getResources();
    outletStates = res.getStringArray(R.array.outlet_spinner);
    adapter = new ArrayAdapter<String>(mActivity, android.R.layout.simple_spinner_item, outletStates);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}

From source file:com.sunny.newmovierecommendation.NewMovieRecommendationActivity.java

private void movieListView() {
    // TODO Auto-generated method stub
    String[] buttons = getResources().getStringArray(R.array.main_buttons);
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_view, buttons));

    lv = getListView();//w w  w . ja  v a  2s  . com
    lv.setTextFilterEnabled(true);
    // lv.setVisibility(View.INVISIBLE); 

    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            MovieScreen.setListValue(id);

            if (id != 0) {
                Intent i = new Intent(NewMovieRecommendationActivity.this, MovieScreen.class);
                startActivity(i);
            } else {

                RecommendGenre recGenre = new RecommendGenre(gender);
                MovieRecommendationScreen movieRec = new MovieRecommendationScreen();
                movieRec.setList(recGenre.recommendGenre());
                Intent i = new Intent(NewMovieRecommendationActivity.this, MovieRecommendationScreen.class);
                startActivity(i);
            }

        }
    });

}

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

private void setListAdapter() {

    Log.d(TAG, "setListAdapter");

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.places_row_layout, placesList) {

        @Override// w  w w .  j  av  a  2  s .c om
        public View getView(int position, View unusedView, ViewGroup parent) {

            View convertView = getActivity().getLayoutInflater().inflate(R.layout.places_row_layout, parent,
                    false);
            AQuery aq = new AQuery(getActivity(), convertView);

            final String placeName = getItem(position);
            aq.id(R.id.place_name).text(placeName);

            aq.id(R.id.places_context_menu_button).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.showContextMenu();
                }
            });

            Log.d(TAG, "Plane name: " + placeName);
            Log.d(TAG, "peopleInsidePlace? " + peopleInsidePlace.has(placeName));

            if (peopleInsidePlace.has(placeName)) { // People are inside this place
                Log.d(TAG, "Inside loop");
                try {
                    JSONArray people = peopleInsidePlace.getJSONArray(placeName);
                    LinearLayout avatarRow = (LinearLayout) convertView.findViewById(R.id.avatar_row);
                    avatarRow.removeAllViewsInLayout(); // Deletes old avatars, if any.

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

                        final String email = people.getString(i);
                        if (MainApplication.iDontWantToSee.has(email)) {
                            continue;
                        }
                        RoundedImageView image = createAvatar(email);

                        if (MainApplication.avatarCache.get(email) != null) {
                            image.setImageBitmap(MainApplication.avatarCache.get(email));
                        } else {
                            Log.d(TAG, "Avatar not in cache, email: " + email);
                            image.setImageResource(R.drawable.default_avatar);
                        }
                        image.setContentDescription(email);

                        avatarRow.addView(image);
                    }

                } catch (Exception ex) {
                    Log.d(TAG, "Error in adding avatars");
                }
            }

            return convertView;
        }
    };

    listView.setAdapter(adapter);

}

From source file:net.dahanne.android.google.client.GoogleActivity.java

private void showGoogleOptions() {
    Connection<Google> findPrimaryConnection = connectionRepository.findPrimaryConnection(Google.class);
    Log.e(TAG, findPrimaryConnection.getDisplayName());

    String[] options = { "Disconnect", "Profile" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);/*from  w  w  w .j a va  2  s .c om*/
    ListView listView = (ListView) this.findViewById(R.id.google_activity_options_list);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            Intent intent;
            switch (position) {
            case 0:
                disconnect();
                showConnectOption();
                break;
            case 1:
                intent = new Intent();
                intent.setClass(parentView.getContext(), GoogleProfileActivity.class);
                startActivity(intent);
                break;
            default:
                break;
            }
        }
    });
}

From source file:at.bitfire.davdroid.ui.CreateAddressBookActivity.java

@Override
public void onLoadFinished(Loader<AccountInfo> loader, AccountInfo info) {
    if (info != null) {
        Spinner spinner = (Spinner) findViewById(R.id.home_sets);
        spinner.setAdapter(//from w  ww  . j  a v  a2  s. c o m
                new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, info.homeSets));
    }
}

From source file:com.qrankforAndroid.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();/* w w  w .  ja  va2 s.  c o m*/

    // \?[X
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);

    // activity_main.xml CAEg?o
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // activity_main.xml Xgr?[?o
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // A_v^?[Zbg
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // ?? position ?@ 0 e\?B
    if (savedInstanceState == null) {

        // APIoRf?[^?B
        task = new GetPosts(MainActivity.this);
        task.execute("0");
    }
}

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipeEditor.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*/* w w w .jav  a2  s  . c  o m*/
     * Creates an Intent to use when the Activity object's result is sent back to the
     * caller.
     */
    final Intent intent = getIntent();

    if (intent.getBooleanExtra(RecipeEditor.NEW_RECIPE, true)) {
        id = null;
        mState = STATE_INSERT;
    } else {

        mState = STATE_EDIT;
        id = intent.getLongExtra(RecipeEditor.RECIPE_ID, 0L);
    }

    // Sets the layout for this Activity. See res/layout/recipe_editor.xml
    setContentView(R.layout.recipe_editor);

    // Gets a handle to the EditText in the the layout.
    mText = (EditText) findViewById(R.id.recipe);

    title = (EditText) findViewById(R.id.title);

    typeSpinner = (Spinner) this.findViewById(R.id.spinner1);

    // Step 2: Create and fill an ArrayAdapter with a bunch of "State" objects
    ArrayAdapter<DishType> spinnerArrayAdapter = new ArrayAdapter<DishType>(this,
            android.R.layout.simple_spinner_item,
            new DishType[] { DishType.ENTREE, DishType.MAIN_DISH, DishType.DESSERT });

    // Step 3: Tell the spinner about our adapter
    typeSpinner.setAdapter(spinnerArrayAdapter);

    /*
     * If this Activity had stopped previously, its state was written the ORIGINAL_CONTENT
     * location in the saved Instance state. This gets the state.
     */
    if (savedInstanceState != null) {
        mOriginalContent = savedInstanceState.getString(ORIGINAL_CONTENT);
    }
}

From source file:com.elkriefy.android.apps.permissionmigrationguide.MainActivity.java

private void populateSpinner() {
    List<String> list = new ArrayList<>();
    list.add("No permissions check");
    list.add("Android Marshmallow permissions");
    list.add("Support Library Permissions");
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(dataAdapter);/*from   www .j  av a  2 s.co m*/
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mGoogleApiClient.isConnected()) {
                mGoogleApiClient.disconnect();
            }
            switch (position) {
            case NO_PERMISSIONS_CHECK:
                mState = NO_PERMISSIONS_CHECK;
                break;
            case MARSHMALLOW_PERMISSIONS_CHECK:
                mState = MARSHMALLOW_PERMISSIONS_CHECK;
                break;
            case SUPPORT_LIBRARY_PERMISSION_CHECK:
                mState = SUPPORT_LIBRARY_PERMISSION_CHECK;
                break;
            }
            mGoogleApiClient.connect();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            if (mGoogleApiClient.isConnected()) {
                mGoogleApiClient.disconnect();
            }
        }
    });
}

From source file:com.example.android.rowanparkingpass.Activities.CreateVehicleActivity.java

private void populateFeilds() {
    make = (EditText) findViewById(R.id.vehicleMakeEditText);
    model = (EditText) findViewById(R.id.modelEditText);
    year = (EditText) findViewById(R.id.yearEditText);
    colorBox = (EditText) findViewById(R.id.vehicleColorEditText);
    state = (Spinner) findViewById(R.id.vehicleSpinner);
    license = (EditText) findViewById(R.id.licenseEditText);
    saveInfo = (CheckBox) findViewById(R.id.saveVehicleInfoOnPhoneCheckBox);
    pastIntent = getIntent();/*from ww  w . j  a v  a  2 s .  com*/
    currentMode = pastIntent.getStringExtra(MODE);
    driver = (Driver) pastIntent.getSerializableExtra("Driver");
    vehicle = (Vehicle) pastIntent.getSerializableExtra("Vehicle");
    ArrayAdapter spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            States.values());
    state.setAdapter(spinnerAdapter);
    cancel = (Button) findViewById(R.id.cancelVehicleButton);
    createVehicle = (Button) findViewById(R.id.createVehicleButton);
    context = getApplicationContext();

}