本文整理汇总了Java中android.widget.ArrayAdapter.add方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayAdapter.add方法的具体用法?Java ArrayAdapter.add怎么用?Java ArrayAdapter.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ArrayAdapter
的用法示例。
在下文中一共展示了ArrayAdapter.add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.list);
listView.setOnItemClickListener(this);
ArrayAdapter<String> demoAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
for (Demo demo : Demo.values()) {
demoAdapter.add(getString(demo.titleResId));
}
listView.setAdapter(demoAdapter);
}
示例2: updateAyahSpinner
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
private void updateAyahSpinner(QuranSpinner spinner,
ArrayAdapter<CharSequence> adapter,
int maxAyah, int currentAyah) {
final Context context = getActivity();
if (context != null) {
CharSequence[] ayahs = new String[maxAyah];
for (int i = 0; i < maxAyah; i++) {
ayahs[i] = QuranUtils.getLocalizedNumber(context, (i + 1));
}
adapter.clear();
for (int i = 0; i < maxAyah; i++) {
adapter.add(ayahs[i]);
}
spinner.setSelection(currentAyah - 1);
}
}
示例3: getDevices
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
public void getDevices() {
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.custom_textview);
list_bt.setAdapter(adapter);
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
adapter.add(device.getName() + "\n" + device.getAddress());
if(device.getName().equals("Synesthesia")) {
devAddress = device.getAddress();
saveAddress(devAddress);
//autoConnect();
// Log.d(TAG, "Addres Device: " + device.getAddress());
//
// btt = new BluetoothThread(device.getAddress(), mHandler);
//
// // Run the thread
// btt.start();
}
}
}
}
示例4: addSpinnerAdapters
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
void addSpinnerAdapters() {
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(),
android.R.layout.simple_spinner_item);
// Populate the month dropdown.
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
SimpleDateFormat formatter = new SimpleDateFormat("MMMM (MM)", Locale.getDefault());
for (int month = 0; month < 12; month++) {
calendar.set(Calendar.MONTH, month);
adapter.add(formatter.format(calendar.getTime()));
}
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mExpirationMonth.setAdapter(adapter);
// Populate the year dropdown.
adapter = new ArrayAdapter<CharSequence>(getActivity(),
android.R.layout.simple_spinner_item);
int initialYear = calendar.get(Calendar.YEAR);
for (int year = initialYear; year < initialYear + 10; year++) {
adapter.add(Integer.toString(year));
}
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mExpirationYear.setAdapter(adapter);
}
示例5: selectDice
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
void selectDice(final DiceSet defaults, boolean hideBtns, final OnDiceChange onOk) {
final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
android.R.layout.simple_spinner_dropdown_item);
dicecache.populate(adapter, hideBtns ? java.util.Arrays.asList(button_cfg)
: new ArrayList<DiceSet>());
adapter.add(getString(R.string.ds_custom));
new AlertDialog.Builder(this)
.setTitle(R.string.ds_choose)
.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String ds = adapter.getItem(which).toString();
Log.d(TAG, "item clicked: " + which + " - " + ds);
if (which == adapter.getCount() - 1)
configureDice(defaults, onOk);
else
onOk.onDiceChange(DiceSet.getDiceSet(ds));
}
})
.setNegativeButton(android.R.string.cancel, null)
.create().show();
}
示例6: onRefreshComplete
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
/**
* When the AsyncTask finishes, it calls onRefreshComplete(), which updates the data in the
* ListAdapter and turns off the progress bar.
*/
private void onRefreshComplete(List<String> result) {
Log.i(LOG_TAG, "onRefreshComplete");
// Remove all items from the ListAdapter, and then replace them with the new items
ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();
adapter.clear();
for (String cheese : result) {
adapter.add(cheese);
}
// Stop the refreshing indicator
setRefreshing(false);
}
示例7: initializeNotificationsList
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
private void initializeNotificationsList() {
listView = (ListView) findViewById(R.id.list_notifications_view);
ArrayAdapter<ConfigurationOption> adapter = new ArrayAdapter<ConfigurationOption>(this.getBaseContext(), android.R.layout.simple_list_item_1);
adapter.add(new ConfigurationOption(IncomingCallConfigActivity.class, getString(R.string.incoming_call_config)));
adapter.add(new ConfigurationOption(WhatsappConfigActivity.class, getString(R.string.whatsapp_config)));
adapter.add(new ConfigurationOption(GenericNotificationsActivity.class, getString(R.string.custom_notification_config)));
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnConfigurationOptionSelected(this, listView));
}
示例8: initializeConfigurationOptions
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
private void initializeConfigurationOptions() {
listView = (ListView) findViewById(R.id.list_config_view);
ArrayAdapter<ConfigurationOption> adapter = new ArrayAdapter<ConfigurationOption>(this.getBaseContext(), android.R.layout.simple_list_item_1);
adapter.add(new ConfigurationOption(NotificationsActivity.class, getString(R.string.notifications_service)));
adapter.add(new ConfigurationOption(ControlModesActivity.class, getString(R.string.phone_control_menu_text)));
adapter.add(new ConfigurationOption(PhoneFinderConfigActivity.class, getString(R.string.phone_finder_service), servicesContainer));
adapter.add(new ConfigurationOption(TimeConfigActivity.class, getString(R.string.time_sync_service)));
adapter.add(new ConfigurationOption(AvailableServicesActivity.class, getString(R.string.show_available_services_text), servicesContainer));
adapter.add(new ConfigurationOption(SettingsActivity.class, getString(R.string.bluewatcher_settings)));
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnConfigurationOptionSelected(this, listView));
}
示例9: reloadHeaderFiltersList
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
private void reloadHeaderFiltersList() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getBaseContext(), android.R.layout.simple_list_item_1);
for (String filter : appConfiguration.getMessageFilters()) {
adapter.add(filter);
}
headerFiltersList.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
示例10: initBLEMeters
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
private int initBLEMeters() {
int adapterCount = 0;
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
mPairedMeterNames = new HashMap<String, String>();
mPairedMeterAddrs = new HashMap<String, String>();
mPairedMeterCount = MeterPreferenceDialog.getPairedMeters(this, mPairedMeterNames, mPairedMeterAddrs);
ArrayAdapter<String> selectedMeterSpinnerAdapter = (ArrayAdapter<String>)mSelectedMeter.getAdapter();
adapterCount = selectedMeterSpinnerAdapter.getCount();
String nameKey;
String addrKey;
String nameValue;
String addrValue;
for (int i=0; i<mPairedMeterCount; i++) {
nameKey = PCLinkLibraryDemoConstant.BLE_PAIRED_METER_NAME_ + String.valueOf(i);
addrKey = PCLinkLibraryDemoConstant.BLE_PAIRED_METER_ADDR_ + String.valueOf(i);
nameValue = mPairedMeterNames.get(nameKey);
addrValue = mPairedMeterAddrs.get(addrKey);
String remoteDeviceName = nameValue + "/" + addrValue;
if (selectedMeterSpinnerAdapter != null) {
boolean find_flag = false;
for (int j=0; j<selectedMeterSpinnerAdapter.getCount(); j++) {
String remoteDeviceName2 = selectedMeterSpinnerAdapter.getItem(j);
if (remoteDeviceName.equals(remoteDeviceName2)) {
find_flag = true;
break;
}
}
if (!find_flag) {
adapterCount++;
selectedMeterSpinnerAdapter.add(remoteDeviceName);
}
}
}
}
return adapterCount;
}
示例11: onStart
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
/**
* Invoked whenever the activity starts
*/
@Override
public void onStart() {
super.onStart();
// Retrieve events
events.clear();
UserAccount currentUser = HabitUpApplication.getCurrentUser();
events.addAll(currentUser.getEventList().getEvents());
// Sort by completedate
Collections.sort(events);
eventAdapter = new EventListAdapter(this, events);
eventListView.setAdapter(eventAdapter);
eventAdapter.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
eventAdapter.setPosition(eventListView.getChildAdapterPosition(v));
return false;
}
});
eventAdapter.setOnItemClickListener(new EventListAdapter.OnItemClickListener() {
@Override
public void onItemClick(View itemView, int pos) {
position = pos;
eventAdapter.setPosition(eventListView.getChildAdapterPosition(itemView));
goToEditActivity(VIEW_EVENT);
}
});
// Display if there are no events
if (events.size() == 0) {
TextView subHeading = (TextView) findViewById(R.id.select_event);
subHeading.setText("You currently have no habit events.");
}
habitTypes = currentUser.getHabitList().getHabits();
// Set up habit type filter spinner
habitSpinner = (Spinner) findViewById(R.id.filter_habit_spinner);
final ArrayAdapter<String> habitAdapter = new ArrayAdapter<>(this, R.layout.habit_spinner);
habitAdapter.add("All Habit Types");
// Set up habit types list
habitTypes = currentUser.getHabitList().getHabits();
// Populate spinner with habit type names
for (Habit habit : habitTypes) {
habitAdapter.add(habit.getHabitName());
}
habitSpinner.setAdapter(habitAdapter);
// Spinner select
habitSpinner.setOnItemSelectedListener(spinnerListener);
commentFilter = (EditText) findViewById(R.id.filter_comment);
commentFilter.setOnKeyListener(cFilter);
// Highlight events row in drawer
navigationView.setCheckedItem(R.id.events);
}
示例12: onOptionsItemSelected
import android.widget.ArrayAdapter; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.select_map_layer:
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), R.layout.setting_spinner_dropdown_item);
arrayAdapter.add(getString(R.string.map_type_topographic));
arrayAdapter.add(getString(R.string.map_type_background));
arrayAdapter.add(getString(R.string.map_type_aerial));
AppPreferences.MapTileSource tileSource = AppPreferences.getMapTileSource(getActivity());
// Defaults to MML topographic
int selectedIndex = 0;
if (tileSource == AppPreferences.MapTileSource.MML_BACKGROUND) {
selectedIndex = 1;
} else if (tileSource == AppPreferences.MapTileSource.MML_AERIAL) {
selectedIndex = 2;
}
new AlertDialog.Builder(getActivity())
.setTitle(getResources().getString(R.string.map_type_select))
.setSingleChoiceItems(arrayAdapter, selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
switch (which) {
case 0:
AppPreferences.setMapTileSource(getActivity(), AppPreferences.MapTileSource.MML_TOPOGRAPHIC);
if (mMapView != null) {
mMapView.setMapTileType(AppPreferences.MapTileSource.MML_TOPOGRAPHIC);
}
break;
case 1:
AppPreferences.setMapTileSource(getActivity(), AppPreferences.MapTileSource.MML_BACKGROUND);
if (mMapView != null) {
mMapView.setMapTileType(AppPreferences.MapTileSource.MML_BACKGROUND);
}
break;
case 2:
AppPreferences.setMapTileSource(getActivity(), AppPreferences.MapTileSource.MML_AERIAL);
if (mMapView != null) {
mMapView.setMapTileType(AppPreferences.MapTileSource.MML_AERIAL);
}
break;
default:
break;
}
}
})
.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}