Java Code Examples for android.widget.ArrayAdapter

The following examples show how to use android.widget.ArrayAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: KinoCast   Source File: DetailActivity.java    License: MIT License 6 votes vote down vote up
private void setMirrorSpinner(Host mirrors[]) {
    if (mirrors != null && mirrors.length > 0) {
        Arrays.sort(mirrors, new WeightedHostComparator(Utils.getWeightedHostList(getApplicationContext())));
        ((Spinner) findViewById(R.id.spinnerMirror)).setAdapter(
                new ArrayAdapter<>(DetailActivity.this, android.R.layout.simple_list_item_1,
                        mirrors));
        findViewById(R.id.spinnerMirror).setEnabled(true);
        findViewById(R.id.buttonPlay).setEnabled(true);
    } else {
        ((Spinner) findViewById(R.id.spinnerMirror)).setAdapter(
                new ArrayAdapter<>(DetailActivity.this, android.R.layout.simple_list_item_1,
                        new String[]{getString(R.string.no_host_found)}));
        findViewById(R.id.spinnerMirror).setEnabled(false);
        findViewById(R.id.buttonPlay).setEnabled(false);
    }
    findViewById(R.id.layoutMirror).setVisibility(View.VISIBLE);
}
 
Example 2
@Override
public void validationAvailable(List<String> items) {
    mUiHandler.post(() -> {
        List<Preference> list = getPreferenceList(getPreferenceScreen(), new ArrayList<>());
        for (Preference p : list) {
            if (p.getKey().endsWith(Constants.PREF_SUFFIX_ITEM) && p instanceof EditTextPreference) {
                final EditText editText = ((EditTextPreference) p).getEditText();

                if (editText instanceof AutoCompleteTextView) {
                    AutoCompleteTextView t = (AutoCompleteTextView) editText;
                    t.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, items));
                    t.performValidation();
                }
            }
        }
    });
}
 
Example 3
Source Project: EhViewer   Source File: GalleryDetailScene.java    License: Apache License 2.0 6 votes vote down vote up
private void bind(Pair<String, String>[] data) {
    if (null == mDialog || null == mProgressView || null == mErrorText || null == mListView) {
        return;
    }

    if (0 == data.length) {
        mProgressView.setVisibility(View.GONE);
        mErrorText.setVisibility(View.VISIBLE);
        mListView.setVisibility(View.GONE);
        mErrorText.setText(R.string.no_archives);
    } else {
        String[] nameArray = new String[data.length];
        for (int i = 0, n = data.length; i < n; i++) {
            nameArray[i] = data[i].second;
        }
        mProgressView.setVisibility(View.GONE);
        mErrorText.setVisibility(View.GONE);
        mListView.setVisibility(View.VISIBLE);
        mListView.setAdapter(new ArrayAdapter<>(mDialog.getContext(), R.layout.item_select_dialog, nameArray));
    }
}
 
Example 4
Source Project: Easer   Source File: WifiSkillViewFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void onResultsAvailable() {
    wait_lock.lock();
    try {
        if (!waiting_for_result)
            return;
        waiting_for_result = false;
    } finally {
        wait_lock.unlock();
    }
    final ArrayAdapter<WifiConfigurationWrapper> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.select_dialog_singlechoice);
    for (WifiConfigurationWrapper wrapper : obtainWifiList()) {
        arrayAdapter.add(wrapper);
    }
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(getContext());
    builderSingle.setTitle(R.string.usource_wificonn_select_dialog_title);
    builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
        @SuppressWarnings("ConstantConditions")
        @Override
        public void onClick(DialogInterface dialog, int which) {
            onWifiSelected(arrayAdapter.getItem(which));
        }
    });
    builderSingle.show();
    progressDialog.dismiss();
}
 
Example 5
Source Project: android-Notifications   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMainRelativeLayout = (RelativeLayout) findViewById(R.id.mainRelativeLayout);
    mNotificationDetailsTextView = (TextView) findViewById(R.id.notificationDetails);
    mSpinner = (Spinner) findViewById(R.id.spinner);

    mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());

    // Create an ArrayAdapter using the string array and a default spinner layout.
    ArrayAdapter<CharSequence> adapter =
            new ArrayAdapter(
                    this,
                    android.R.layout.simple_spinner_item,
                    NOTIFICATION_STYLES);
    // Specify the layout to use when the list of choices appears.
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    mSpinner.setAdapter(adapter);
    mSpinner.setOnItemSelectedListener(this);
}
 
Example 6
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_expandable_list_view);

    ArrayList<Integer> numbersArray = new ArrayList<Integer>();
    ExpandableHeightListView expandableListView = (ExpandableHeightListView) findViewById(R.id.expandable_listview);

    int i;
    for (i=0; i<=20; i++){
        numbersArray.add(i);
    }

    ArrayAdapter<Integer> itemsAdapter =
            new ArrayAdapter<Integer>(this, android.R.layout.simple_list_item_1, numbersArray);

    expandableListView.setAdapter(itemsAdapter);

    // This actually do the magic
    expandableListView.setExpanded(true);
}
 
Example 7
Source Project: FadingActionBar   Source File: ListViewActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FadingActionBarHelper helper = new FadingActionBarHelper()
        .actionBarBackground(R.drawable.ab_background)
        .headerLayout(R.layout.header)
        .contentLayout(R.layout.activity_listview);
    setContentView(helper.createView(this));
    helper.initActionBar(this);

    ListView listView = (ListView) findViewById(android.R.id.list);
    ArrayList<String> items = loadItems(R.raw.nyc_sites);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
    listView.setAdapter(adapter);
}
 
Example 8
Source Project: android_dbinspector   Source File: TableListFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    AppCompatActivity activity = (AppCompatActivity) getActivity();

    List<String> tableList = DatabaseHelper.getAllTables(database);
    String version = DatabaseHelper.getVersion(database);
    ActionBar actionBar = activity.getSupportActionBar();
    if (actionBar != null) {

        actionBar.setTitle(database.getName());
        if (!TextUtils.isEmpty(version)) {
            actionBar.setSubtitle("v" + version);
        }
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, tableList);

    setListAdapter(adapter);
    getListView().setOnItemClickListener(tableClickListener);
}
 
Example 9
Source Project: AndroidDemo   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    textView =  findViewById(R.id.textview);
    spinner = findViewById(R.id.spinner);
    textView.setText("您选择的城市是北京");
    //1.设置数据源
    list = new ArrayList<>();
    list.add("北京");
    list.add("上海");
    list.add("广州");
    list.add("深圳");
    list.add("保定");
    //2.定义适配器
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
    //3.adapter设置下拉样式
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //4.spinner加载适配器
    spinner.setAdapter(adapter);
    //5.spinner设置监听器
    spinner.setOnItemSelectedListener(this);
}
 
Example 10
Source Project: rss   Source File: AsyncNavigationAdapter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected
void onPostExecute(String[][] result)
{
    // Set the titles & counts arrays in this file and notify the adapter.
    ListView navigationList = (ListView) m_activity.findViewById(R.id.fragment_navigation_drawer);
    WrapperListAdapter wrapperAdapter = (WrapperListAdapter) navigationList.getAdapter();
    ArrayAdapter<String[]> adapter = (ArrayAdapter<String[]>) wrapperAdapter.getWrappedAdapter();

    // Update the data in the adapter.
    adapter.clear();
    adapter.addAll(result);

    // Update the subtitle.
    if(Constants.s_fragmentFeeds.isVisible())
    {
        Utilities.setTitlesAndDrawerAndPage(null, -10);
    }
}
 
Example 11
Source Project: SI   Source File: SensorResourceP.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public SensorResourceP(Activity main, Context c, ArrayList<String> list_item,
                       ArrayAdapter<String> list_adapter) {

    super(main, c, list_item, list_adapter);

    resource_type = "gateway.sensorp";
    resource_uri = "/gateway/sensorp";

    mTemp = 0.0;
    mHumidity = 0.0;
    mLight = 0;
    mSound = 0;

    mTempListIndex = -1;
    mHumidityListIndex = -1;
    mLightListIndex = -1;
    mSoundListIndex = -1;

    msg_content_found = "msg_found_sensor_p";

    msg_type_get_done = "msg_get_done_sensor_p";
    update_thread_done = true;

    LocalBroadcastManager.getInstance(main_activity).registerReceiver(mSensorReadReceiver,
            new IntentFilter(msg_type_get_done));
}
 
Example 12
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    settingsHelper = new SettingsHelper(getApplicationContext());
    listType = settingsHelper.getListType();
    ArrayList<String> listItems = new ArrayList<String>(settingsHelper.getListItems(listType));
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
    setListAdapter(adapter);

    float scale = getResources().getDisplayMetrics().density;
    int padding = (int) (8 * scale + 0.5f);
    getListView().setPadding(padding * 2, padding, padding * 2, padding);
    getListView().setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    if (listType.equals(Common.PREF_BLACKLIST))
        setTitle(R.string.list_type_entries_blacklist);
    else
        setTitle(R.string.list_type_entries_whitelist);
}
 
Example 13
Source Project: freeiot-android   Source File: NavigationDrawerFragment.java    License: MIT License 6 votes vote down vote up
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mDrawerListView = (ListView) inflater.inflate(
                R.layout.fragment_navigation_drawer, container, false);
        mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectItem(position);
            }
        });
        mDrawerListView.setAdapter(new ArrayAdapter<String>(
                getActionBar().getThemedContext(),
                R.layout.adapter_navigation_drawer,
//                android.R.layout.simple_list_item_1,
                android.R.id.text1,
                new String[]{
                        getString(R.string.my_devices),
                        getString(R.string.logout),
                }));
        mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
        return mDrawerListView;
    }
 
Example 14
@Override
public void onItemSelected(AdapterView<?> parent, View callingView, int pos, long arg3) {
    if (parent == mainComboSpinner) {
        String mainComboItem = mainComboSpinner.getSelectedItem().toString();

        List<NamedList<String>> namedLists = new ArrayList<>();
        if (mainComboItem.length() != 0) {
            namedLists = dataMap.get(mainComboItem);
        }
        for (int i = 0; i < namedLists.size(); i++) {
            NamedList<String> namedList = namedLists.get(i);
            TextView subTextView = orderedSubTextviewsList.get(i);
            subTextView.setText(namedList.name);

            Spinner subSpinner = orderedSubCombosList.get(i);
            ArrayAdapter<String> combo2ListAdapter = new ArrayAdapter<String>(parent.getContext(), android.R.layout.simple_spinner_dropdown_item, namedList.items);
            combo2ListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            subSpinner.setAdapter(combo2ListAdapter);
        }
    }
}
 
Example 15
public void setItems(final CharSequence[] items,
                     final AdapterView.OnItemClickListener listener) {
    mAdapter = new ArrayAdapter<CharSequence>(getContext(), android.R.layout.simple_list_item_1, items) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            if (view != null) {
                TextView tv = (TextView) view.findViewById(android.R.id.text1);
                if (mListItemTextStyle != 0) {
                    tv.setTextAppearance(getContext(), mListItemTextStyle);
                }
                tv.setText(items[position]);
            }
            return view;
        }
    };
    mListItemListener = listener;
}
 
Example 16
Source Project: MHViewer   Source File: GalleryDetailScene.java    License: Apache License 2.0 6 votes vote down vote up
private void bind(Pair<String, String>[] data) {
    if (null == mDialog || null == mProgressView || null == mErrorText || null == mListView) {
        return;
    }

    if (0 == data.length) {
        mProgressView.setVisibility(View.GONE);
        mErrorText.setVisibility(View.VISIBLE);
        mListView.setVisibility(View.GONE);
        mErrorText.setText(R.string.no_torrents);
    } else {
        String[] nameArray = new String[data.length];
        for (int i = 0, n = data.length; i < n; i++) {
            nameArray[i] = data[i].second;
        }
        mProgressView.setVisibility(View.GONE);
        mErrorText.setVisibility(View.GONE);
        mListView.setVisibility(View.VISIBLE);
        mListView.setAdapter(new ArrayAdapter<>(mDialog.getContext(), R.layout.item_select_dialog, nameArray));
    }
}
 
Example 17
Source Project: FadingActionBar   Source File: HeaderOverlayActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FadingActionBarHelper helper = new FadingActionBarHelper()
        .actionBarBackground(R.drawable.ab_background)
        .headerLayout(R.layout.header)
        .contentLayout(R.layout.activity_listview)
        .headerOverlayLayout(R.layout.header_overlay);
    setContentView(helper.createView(this));
    helper.initActionBar(this);

    ListView listView = (ListView) findViewById(android.R.id.list);
    ArrayList<String> items = loadItems(R.raw.nyc_sites);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
    listView.setAdapter(adapter);
}
 
Example 18
Source Project: PullRefreshView   Source File: ScrollerEpActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scroller_ep);
    listView = (ListView) findViewById(R.id.list);
    headerView = (BaseHeaderView) findViewById(R.id.header);
    footerView = (BaseFooterView) findViewById(R.id.footer);

    list = getData(15);

    adapter = new ArrayAdapter(this, R.layout.item, list);

    listView.setAdapter(adapter);

    headerView.setOnRefreshListener(this);
    footerView.setOnLoadListener(this);
}
 
Example 19
Source Project: user-interface-samples   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMainRelativeLayout = (RelativeLayout) findViewById(R.id.mainRelativeLayout);
    mNotificationDetailsTextView = (TextView) findViewById(R.id.notificationDetails);
    mSpinner = (Spinner) findViewById(R.id.spinner);

    mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());

    // Create an ArrayAdapter using the string array and a default spinner layout.
    ArrayAdapter<CharSequence> adapter =
            new ArrayAdapter(
                    this,
                    android.R.layout.simple_spinner_item,
                    NOTIFICATION_STYLES);
    // Specify the layout to use when the list of choices appears.
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    mSpinner.setAdapter(adapter);
    mSpinner.setOnItemSelectedListener(this);
}
 
Example 20
Source Project: GSYVideoPlayer   Source File: SwitchVideoTypeDialog.java    License: Apache License 2.0 6 votes vote down vote up
public void initList(List<SwitchVideoModel> data, OnListItemClickListener onItemClickListener) {
    this.onItemClickListener = onItemClickListener;
    this.data = data;

    LayoutInflater inflater = LayoutInflater.from(mContext);
    View view = inflater.inflate(R.layout.switch_video_dialog, null);
    listView = (ListView) view.findViewById(R.id.switch_dialog_list);
    setContentView(view);
    adapter = new ArrayAdapter<>(mContext, R.layout.switch_video_dialog_item, data);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener());

    Window dialogWindow = getWindow();
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    DisplayMetrics d = mContext.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
    lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
    dialogWindow.setAttributes(lp);
}
 
Example 21
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_movie);

    mTextureView = (TextureView) findViewById(R.id.movie_texture_view);
    mTextureView.setSurfaceTextureListener(this);

    // Populate file-selection spinner.
    Spinner spinner = (Spinner) findViewById(R.id.playMovieFile_spinner);
    // Need to create one of these fancy ArrayAdapter thingies, and specify the generic layout
    // for the widget itself.
    mMovieFiles = MiscUtils.getFiles(Environment.getExternalStorageDirectory(), "*.mp4");
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, mMovieFiles);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    updateControls();
}
 
Example 22
Source Project: AndroidDemoProjects   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    mListView = (ListView) findViewById(R.id.list);

    mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new ArrayList<String>());

    mAdapter.add("Movie 1");
    mAdapter.add("Movie 2");
    mAdapter.add("Movie 3");
    mAdapter.add("Movie 4");
    mAdapter.add("Movie 5");
    mAdapter.add("Movie 6");
    mAdapter.add("Movie 7");

    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(this);

    CastContext.getSharedInstance(this).addCastStateListener(this);
    CastContext.getSharedInstance(this).addAppVisibilityListener(this);
    CastContext.getSharedInstance(this).getSessionManager().addSessionManagerListener(this);
}
 
Example 23
Source Project: photon   Source File: TransmitActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transmit);


    // Code for spinner
    Spinner mySpinner = (Spinner) findViewById(R.id.myspinner);
    ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(TransmitActivity.this, android.R.layout.simple_list_item_1,
            getResources().getStringArray(R.array.menu_items));
    myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mySpinner.setAdapter(myAdapter);
    mySpinner.setOnItemSelectedListener(this);
    //Code for drop down ends, onSelect methods at buttom

    // TODO: Create an alert if flashlight is not present in device
    // TODO: Exit the app if no flashlight
    boolean hasFlash = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
    Log.d("Has Flashlight:", Boolean.toString(hasFlash));
    if (!hasFlash) {
        showNoFlashLightAlert();
    }
}
 
Example 24
public void refreshActivityScreenPosture(final String posture)
{
    runOnUiThread(new Runnable()
    {
        @Override
        public void run()
        {
            @SuppressWarnings( "unchecked" )  // it is save
                    ArrayAdapter<String> postureAdapter = (ArrayAdapter<String>) AdapterController.getInstance().get("ActivityScreenPosture");
            if(postureAdapter == null) {
                return;
            }
            postureAdapter.clear();
            postureAdapter.add(posture);
            postureAdapter.notifyDataSetChanged();
        }
    });
}
 
Example 25
Source Project: PullRefreshView   Source File: Fragment0.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment0, container, false);
    listView = findViewById(R.id.list);
    headerView = findViewById(R.id.header);
    footerView = findViewById(R.id.footer);

    list = getData(15);

    adapter = new ArrayAdapter(getContext(), R.layout.item, list);

    listView.setAdapter(adapter);

    headerView.setOnRefreshListener(this);
    footerView.setOnLoadListener(this);
    return view;
}
 
Example 26
Source Project: accountBook   Source File: CountActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 初始化spinner
 */
private void initSpinner(){
    month_spinner = (Spinner) findViewById(R.id.month_spinner);
    //将可选内容与ArrayAdapter连接起来
    month_adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, monthList);
    //设置下拉列表的风格
    month_adapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //将adapter添加到spinner中
    month_spinner.setAdapter(month_adapter);
    //添加事件Spinner事件监听
    month_spinner
            .setOnItemSelectedListener(new month_spinnerSelectedListener());
    //设置默认值
    month_spinner.setSelection(pubFun.getTime("M"), true);
    month_spinner.setVisibility(View.VISIBLE);
}
 
Example 27
Source Project: gsn   Source File: ActivityPublishData.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void renderVSList() {

		new AsyncTask<AndroidControllerPublish, Void, ArrayList<String>>() {
			@Override
			protected ArrayList<String> doInBackground(AndroidControllerPublish... params) {
				return params[0].loadListVS();
			}

			@Override
			protected void onPostExecute(ArrayList<String> result) {
				ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(ActivityPublishData.this, R.layout.spinner_item, result);
				dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				vsnameSpinner.setAdapter(dataAdapter);
				if (dr != null) {
					int p = dataAdapter.getPosition(dr.getVsname());
					if (p != -1) {
						vsnameSpinner.setSelection(p);
					}
				}
			}
		}.execute(controller);
	}
 
Example 28
Source Project: journaldev   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Spinner element
    final Spinner spinner = (Spinner) findViewById(R.id.spinner);
    Button button=(Button)findViewById(R.id.button);

    // Spinner click listener
    spinner.setOnItemSelectedListener(this);

    // Spinner Drop down elements
    List<String> categories = new ArrayList<String>();
    categories.add("Item 1");
    categories.add("Item 2");
    categories.add("Item 3");
    categories.add("Item 4");
    categories.add("Item 5");
    categories.add("Item 6");

    // Creating adapter for spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent= new Intent(MainActivity.this,SecondActivity.class);
            intent.putExtra("data",String.valueOf(spinner.getSelectedItem()));
            startActivity(intent);
        }
    });
}
 
Example 29
public void fillFactories() {
	ArrayAdapter<TGSelectableItem> arrayAdapter = new ArrayAdapter<TGSelectableItem>(getActivity(), android.R.layout.simple_spinner_item, createFactoryValues());
	arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	
	Spinner spinner = (Spinner) this.getView().findViewById(R.id.browser_collections_dlg_add_type);
	spinner.setAdapter(arrayAdapter);
}
 
Example 30
Source Project: SegmentedButton   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initialize all variables annotated with @BindView and other variants
    ButterKnife.bind(this);

    ArrayList<String> spinnerItems = new ArrayList<>();

    for (Action action : Action.values())
    {
        spinnerItems.add(action.getDisplayText());
    }

    ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, spinnerItems);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    updateButton(gradientButtonGroup.getPosition());
    gradientButtonGroup.setOnPositionChangedListener(position -> updateButton(position));

    setupDynamicDrawables();
    setupYesNoMaybePButtonGroup();
    setupStarWarsPButtonGroup();
    setupCountPButtonGroup();

    // Basic checks
    if (starWarsButtonGroup.getButtons().size() != 3)
    {
        throw new AssertionError("Buttons size incorrect");
    }

    if (!lordOfTheRingsButtonGroup.getButton(1).getText().equals("Gimli"))
    {
        throw new AssertionError("Button name is incorrect");
    }
}