List of usage examples for android.widget NumberPicker setDescendantFocusability
public void setDescendantFocusability(int focusability)
From source file:com.matthewmitchell.wakeifyplus.MinutesSecondsFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { TableRow.LayoutParams twoLP = new TableRow.LayoutParams(0, 0, 0.2f); TableRow.LayoutParams threeLP = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 0.3f); View spacer = new View(activity); spacer.setLayoutParams(twoLP);/*from w w w. ja va2 s . c o m*/ spacer.setVisibility(View.INVISIBLE); final NumberPicker minutes = new NumberPicker(activity); minutes.setMaxValue(30); minutes.setMinValue(0); minutes.setValue(defaultMinute); minutes.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); LinearLayout minutesLayout = new LinearLayout(activity); minutesLayout.addView(minutes); minutesLayout.setGravity(Gravity.CENTER); minutesLayout.setLayoutParams(threeLP); final NumberPicker seconds = new NumberPicker(activity); seconds.setMaxValue(59); seconds.setMinValue(0); seconds.setValue(defaultSecond); seconds.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); LinearLayout secondsLayout = new LinearLayout(activity); secondsLayout.addView(seconds); secondsLayout.setGravity(Gravity.CENTER); secondsLayout.setLayoutParams(threeLP); LinearLayout layout = new LinearLayout(activity); layout.addView(spacer); layout.addView(minutesLayout); layout.addView(secondsLayout); layout.setWeightSum(1.0f); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage("Set Volume Ramping Time").setView(layout) .setPositiveButton("Set", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { activity.rampingMinutes = minutes.getValue(); activity.rampingSeconds = seconds.getValue(); TextView edit = (TextView) activity.findViewById(R.id.volume_ramping); edit.setText(activity.rampingMinutes + "m" + activity.rampingSeconds + "s"); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Do nothing. } }); // Create the AlertDialog object and return it return builder.create(); }
From source file:ca.mudar.parkcatcher.ui.fragments.NumberPickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { ((ParkingApp) getActivity().getApplicationContext()).updateUiLanguage(); LayoutInflater factory = LayoutInflater.from(getActivity()); final View view = factory.inflate(R.layout.fragment_number_picker, null); final NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.number_picker_duration); numberPicker.setMinValue(Const.DURATION_MIN); numberPicker.setMaxValue(Const.DURATION_MAX); numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); int currentDuration = mListener.getParkingDuration(); numberPicker.setValue(currentDuration); return new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.dialog_title_duration)) .setView(view).setPositiveButton(R.string.dialog_done, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { onDurationSet(numberPicker); }/*w w w. j a va2s .c o m*/ }).create(); }
From source file:org.tomasdavid.vehicleroutingproblem.fragments.MainFragment.java
/** * {@inheritDoc}//from w w w. j a v a 2 s . c om */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_main, container, false); // time limit number picker initialization NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.timeLimitPicker); numberPicker.setMinValue(MIN_TIME_LIMIT); numberPicker.setMaxValue(MAX_TIME_LIMIT); numberPicker.setValue(DEFAULT_TIME_LIMIT); numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // welcome text TextView welcomeText = (TextView) view.findViewById(R.id.welcome_text); welcomeText.setText(Html.fromHtml(getString(R.string.welcome_text))); // spinner for choosing algorithm initialization Spinner algSpinner = (Spinner) view.findViewById(R.id.algorithm_spinner); ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.algorithms, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); algSpinner.setAdapter(spinnerAdapter); setHasOptionsMenu(true); return view; }
From source file:com.crcrch.chromatictuner.app.NotePickerFragment.java
@NonNull @Override/*from w w w .j a v a2 s . c o m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); View dialogContent = LayoutInflater.from(dialogBuilder.getContext()).inflate(R.layout.fragment_note_picker, null); final NumberPicker notePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_note); notePicker.setMinValue(0); notePicker.setMaxValue(MiscMusic.CHROMATIC_SCALE.length - 1); notePicker.setDisplayedValues(MiscMusic.CHROMATIC_SCALE); notePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final NumberPicker octavePicker = (NumberPicker) dialogContent.findViewById(R.id.picker_octave); octavePicker.setMinValue(0); octavePicker.setMaxValue(MAX_OCTAVE); octavePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); octavePicker.setWrapSelectorWheel(false); final TextView frequencyView = (TextView) dialogContent.findViewById(R.id.frequency); notePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { frequencyView.setText(selectFrequency(newVal, octavePicker.getValue())); } }); octavePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { frequencyView.setText(selectFrequency(notePicker.getValue(), newVal)); } }); double frequencyToDisplay; if (savedInstanceState == null) { frequencyToDisplay = initialFrequency; } else { frequencyToDisplay = savedInstanceState.getDouble(STATE_FREQUENCY); } frequencyView.setText(selectFrequency(frequencyToDisplay)); int note = getNoteForFrequency(frequencyToDisplay); octavePicker.setValue(getOctaveForNote(note)); octavePicker.invalidate(); notePicker.setValue(getNoteIndexForNote(note)); notePicker.invalidate(); return dialogBuilder.setTitle(R.string.dialog_title_note_picker).setView(dialogContent) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { listener.onFrequencySelected(frequency); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, null).create(); }
From source file:com.yacorso.nowaste.views.adapters.FridgeFoodAdapter.java
@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) { final FridgeViewHolder holder = (FridgeViewHolder) viewHolder; final Food food = foodList.get(position); final int quantity = food.getFoodFridge().getQuantity(); holder.tvName.setText(food.getName()); holder.btnQuantity.setText(Integer.toString(quantity)); Date outOfDate = food.getFoodFridge().getOutOfDate(); holder.outOfDate.setText(getDateTextFromDate(outOfDate)); setOpenIcon(holder.btnOpenToggle, food); setColorCircleFromDate(holder.btnQuantity, outOfDate, mContext.getResources()); View.OnClickListener clickListener = new View.OnClickListener() { @Override//from www . ja va 2 s . c o m public void onClick(View v) { lastFoodClickedPosition = position; switch (v.getId()) { case R.id.btn_food_quantity: /* * Popup changement quantit */ final NumberPicker numberPicker = new NumberPicker(mContext); numberPicker.setMinValue(1); numberPicker.setMaxValue(100); numberPicker.setValue(quantity); numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.title_quantity_number_picker); builder.setView(numberPicker); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* * Save the modification */ int selectedValue = numberPicker.getValue(); food.getFoodFridge().setQuantity(selectedValue); mFoodProvider.update(food); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.create().show(); break; case R.id.btn_open_toggle: /* * Open/close food */ FoodFridge foodFridge = food.getFoodFridge(); foodFridge.toggleOpen(); setOpenIcon(v, food); Date outOfDate = foodFridge.getOutOfDate(); setColorCircleFromDate(holder.btnQuantity, outOfDate, v.getResources()); mFoodProvider.update(food); break; case R.id.item_text_zone: EventBus.getDefault().post(new CallUpdateFoodEvent(food)); break; case R.id.btn_favorite_toggle: EventBus.getDefault().post(new CallAddFoodToCustomListEvent(food)); break; } } }; holder.btnQuantity.setOnClickListener(clickListener); holder.btnOpenToggle.setOnClickListener(clickListener); holder.btnFavoriteToggle.setOnClickListener(clickListener); holder.textZone.setOnClickListener(clickListener); }
From source file:com.untie.daywal.activity.MainActivity.java
private void showDayPicker() { Calendar calender = Calendar.getInstance(); pickedYear = calender.get(Calendar.YEAR); pickedMonth = calender.get(Calendar.MONTH) + 1; final Dialog dayPickerDialog = new Dialog(this); dayPickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dayPickerDialog.setContentView(R.layout.dialog); Button okBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_ok); Button cancelBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_cancel); dialog_year_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_year_title); dialog_month_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_month_title); final NumberPicker yearPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.yearPicker); final NumberPicker monthPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.monthPicker); dialog_year_title.setText(String.valueOf(pickedYear) + ""); dialog_month_title.setText(String.valueOf(pickedMonth) + ""); yearPicker.setMinValue(pickedYear - 100); yearPicker.setMaxValue(pickedYear + 40); yearPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // setDividerColor(yearPicker, android.R.color.white ); yearPicker.setWrapSelectorWheel(false); yearPicker.setValue(pickedYear);/*from ww w .j a va 2 s. c o m*/ yearPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { dialog_year_title.setText(String.valueOf(newVal) + ""); } }); monthPicker.setMinValue(1); monthPicker.setMaxValue(12); monthPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // setDividerColor(monthPicker, android.R.color.white); //monthPicker.setWrapSelectorWheel(false); monthPicker.setValue(pickedMonth); monthPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { dialog_month_title.setText(String.valueOf(newVal) + ""); } }); okBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO : ?? yearPicker.getValue() monthPicker.getValue() //Toast.makeText(MainActivity.this, String.valueOf(yearPicker.getValue())+"/"+monthPicker.getValue(), Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, MainActivity.class); intent.putExtra("year", yearPicker.getValue()); intent.putExtra("month", monthPicker.getValue()); intent.putExtra("order", 1); dayPickerDialog.dismiss(); startActivity(intent); overridePendingTransition(0, 0); } }); cancelBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dayPickerDialog.dismiss(); } }); dayPickerDialog.show(); }
From source file:com.jaguarlandrover.hvacdemo.MainActivity.java
private void configurePicker(NumberPicker picker) { picker.setMinValue(15);/*from ww w . ja v a 2s .c o m*/ picker.setMaxValue(29); picker.setWrapSelectorWheel(false); picker.setDisplayedValues(new String[] { "LO", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "HI" }); picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { /* USER INTERFACE CALLBACK */ @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { Log.d(TAG, Util.getMethodName()); HVACManager.invokeService(getServiceIdentifiersFromViewId(picker.getId()), Integer.toString(newVal)); } }); }
From source file:butter.droid.base.fragments.dialog.NumberPickerDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (getArguments() == null || !getArguments().containsKey(MAX_VALUE) || !getArguments().containsKey(MIN_VALUE) || !getArguments().containsKey(TITLE) || mOnResultListener == null) { return builder.create(); }//from w ww . ja v a 2s .c o m final NumberPicker numberPicker = new NumberPicker(getActivity()); numberPicker.setLayoutParams(new NumberPicker.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); numberPicker.setWrapSelectorWheel(false); final int minValue = getArguments().getInt(MIN_VALUE); final int maxValue = getArguments().getInt(MAX_VALUE); final int currentValue = getArguments().getInt(DEFAULT_VALUE, (int) Math.floor((numberPicker.getMaxValue() - numberPicker.getMinValue()) / 2)); List<String> displayValues = new ArrayList<>(); for (int i = minValue; i < maxValue + 1; i++) { displayValues.add(Integer.toString(i)); } numberPicker.setDisplayedValues(displayValues.toArray(new String[displayValues.size()])); if (minValue < 0) { numberPicker.setMinValue(0); numberPicker.setMaxValue(maxValue + Math.abs(minValue)); numberPicker.setValue(currentValue + Math.abs(minValue)); } else { numberPicker.setMinValue(minValue); numberPicker.setMaxValue(maxValue); numberPicker.setValue(currentValue); } if (getArguments().containsKey(FOCUSABLE) && !getArguments().getBoolean(FOCUSABLE)) numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); builder.setView(numberPicker).setTitle(getArguments().getString(TITLE)) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mOnResultListener.onNewValue(numberPicker.getValue() + (minValue < 0 ? minValue : 0)); dialog.dismiss(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); return builder.create(); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
public void TimeLapseDialog() { if (isRecording) return;/* w ww.j a v a 2 s . c om*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()); interval = Integer.valueOf(prefs.getString("timelapseInterval", "0")); measurementVal = Integer.valueOf(prefs.getString("timelapseMeasurementVal", "0")); // show time lapse settings timeLapseDialog = new TimeLapseDialog(ApplicationScreen.instance); timeLapseDialog.setContentView(R.layout.plugin_capture_video_timelapse_dialog); final NumberPicker np = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker1); np.setMaxValue(16); np.setMinValue(0); np.setValue(interval); np.setDisplayedValues(stringInterval); np.setWrapSelectorWheel(false); np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final NumberPicker np2 = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker2); np2.setMaxValue(2); np2.setMinValue(0); np2.setValue(measurementVal); np2.setWrapSelectorWheel(false); np2.setDisplayedValues(stringMeasurement); np2.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final Switch sw = (Switch) timeLapseDialog.findViewById(R.id.timelapse_switcher); // disable/enable controls in dialog sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!sw.isChecked()) { swChecked = false; } else { swChecked = true; } } }); np2.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); np.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); // disable control in dialog by default if (!swChecked) { sw.setChecked(false); } else { sw.setChecked(true); } timeLapseDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (swChecked) { measurementVal = np2.getValue(); interval = np.getValue(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ApplicationScreen.getMainContext()); Editor editor = prefs.edit(); editor.putString("timelapseMeasurementVal", String.valueOf(measurementVal)); editor.putString("timelapseInterval", String.valueOf(interval)); editor.commit(); timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_active)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } else { timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_inactive)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } } }); timeLapseDialog.show(); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void sortChannels() { ContentResolver cr = getContentResolver(); StringBuilder where = new StringBuilder(TvBrowserContentProvider.CHANNEL_KEY_SELECTION); where.append("=1"); LinearLayout main = (LinearLayout) getLayoutInflater().inflate(R.layout.channel_sort_list, getParentViewGroup(), false); Button sortAlphabetically = (Button) main.findViewById(R.id.channel_sort_alpabetically); final DynamicListView channelSort = (DynamicListView) main.findViewById(R.id.channel_sort); String[] projection = { TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.CHANNEL_KEY_NAME, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER, TvBrowserContentProvider.CHANNEL_KEY_SELECTION, TvBrowserContentProvider.CHANNEL_KEY_LOGO }; Cursor channels = cr.query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, projection, where.toString(), null, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER); final ArrayList<SortInterface> channelSource = new ArrayList<SortInterface>(); if (channels.moveToFirst()) { do {// w w w . j a v a2 s. co m int key = channels.getInt(0); String name = channels.getString(1); int order = 0; if (!channels.isNull(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER))) { order = channels .getInt(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER)); } Bitmap channelLogo = UiUtils.createBitmapFromByteArray( channels.getBlob(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_LOGO))); if (channelLogo != null) { BitmapDrawable l = new BitmapDrawable(getResources(), channelLogo); ColorDrawable background = new ColorDrawable(SettingConstants.LOGO_BACKGROUND_COLOR); background.setBounds(0, 0, channelLogo.getWidth() + 2, channelLogo.getHeight() + 2); LayerDrawable logoDrawable = new LayerDrawable(new Drawable[] { background, l }); logoDrawable.setBounds(background.getBounds()); l.setBounds(2, 2, channelLogo.getWidth(), channelLogo.getHeight()); channelLogo = UiUtils.drawableToBitmap(logoDrawable); } channelSource.add(new ChannelSort(key, name, order, channelLogo)); } while (channels.moveToNext()); channels.close(); final Comparator<SortInterface> sortComparator = new Comparator<SortInterface>() { @Override public int compare(SortInterface lhs, SortInterface rhs) { if (lhs.getSortNumber() < rhs.getSortNumber()) { return -1; } else if (lhs.getSortNumber() > rhs.getSortNumber()) { return 1; } return 0; } }; Collections.sort(channelSource, sortComparator); // create default logo for channels without logo final Bitmap defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); final StableArrayAdapter<SortInterface> aa = new StableArrayAdapter<SortInterface>(TvBrowser.this, R.layout.channel_sort_row, channelSource) { public View getView(int position, View convertView, ViewGroup parent) { ChannelSort value = (ChannelSort) getItem(position); ViewHolder holder = null; if (convertView == null) { LayoutInflater mInflater = (LayoutInflater) getContext() .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.channel_sort_row, getParentViewGroup(), false); holder.mTextView = (TextView) convertView.findViewById(R.id.row_of_channel_sort_text); holder.mSortNumber = (TextView) convertView.findViewById(R.id.row_of_channel_sort_number); holder.mLogo = (ImageView) convertView.findViewById(R.id.row_of_channel_sort_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.mTextView.setText(value.getName()); String sortNumber = String.valueOf(value.getSortNumber()); if (value.getSortNumber() == 0) { sortNumber = "-"; } sortNumber += "."; holder.mSortNumber.setText(sortNumber); Bitmap logo = value.getLogo(); if (logo != null) { holder.mLogo.setImageBitmap(logo); } else { holder.mLogo.setImageBitmap(defaultLogo); } return convertView; } }; channelSort.setAdapter(aa); channelSort.setArrayList(channelSource); channelSort.setSortDropListener(new SortDropListener() { @Override public void dropped(int originalPosition, int position) { int startIndex = originalPosition; int endIndex = position; int droppedPos = position; if (originalPosition > position) { startIndex = position; endIndex = originalPosition; } int previousNumber = 0; if (startIndex > 0) { previousNumber = aa.getItem(startIndex - 1).getSortNumber(); } int firstVisible = channelSort.getFirstVisiblePosition(); for (int i = startIndex; i <= endIndex; i++) { if (i == droppedPos || aa.getItem(i).getSortNumber() != 0) { aa.getItem(i).setSortNumber(++previousNumber); if (i >= firstVisible) { View line = channelSort.getChildAt(i - firstVisible); if (line != null) { ((TextView) line.findViewById(R.id.row_of_channel_sort_number)) .setText(String.valueOf(previousNumber) + "."); } } } } } }); channelSort.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapterView, final View view, final int position, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); LinearLayout numberSelection = (LinearLayout) getLayoutInflater() .inflate(R.layout.sort_number_selection, getParentViewGroup(), false); mSelectionNumberChanged = false; final NumberPicker number = (NumberPicker) numberSelection.findViewById(R.id.sort_picker); number.setMinValue(1); number.setMaxValue(channelSource.size()); number.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); number.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() { @Override public void onValueChange(NumberPicker picker, int oldVal, int newVal) { mSelectionNumberChanged = true; } }); final EditText numberAlternative = (EditText) numberSelection .findViewById(R.id.sort_entered_number); builder.setView(numberSelection); final ChannelSort selection = (ChannelSort) channelSource.get(position); TextView name = (TextView) numberSelection.findViewById(R.id.sort_picker_channel_name); name.setText(selection.getName()); if (selection.getSortNumber() > 0) { if (selection.getSortNumber() < channelSource.size() + 1) { number.setValue(selection.getSortNumber()); } else { numberAlternative.setText(String.valueOf(selection.getSortNumber())); } } builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String test = numberAlternative.getText().toString().trim(); if (test.length() == 0 || mSelectionNumberChanged) { selection.setSortNumber(number.getValue()); } else { try { selection.setSortNumber(Integer.parseInt(test)); } catch (NumberFormatException e1) { } } Collections.sort(channelSource, sortComparator); aa.notifyDataSetChanged(); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } }); sortAlphabetically.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collections.sort(channelSource, new Comparator<SortInterface>() { @Override public int compare(SortInterface lhs, SortInterface rhs) { return lhs.getName().compareToIgnoreCase(rhs.getName()); } }); for (int i = 0; i < channelSource.size(); i++) { channelSource.get(i).setSortNumber(i + 1); } aa.notifyDataSetChanged(); } }); AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); builder.setTitle(R.string.action_sort_channels); builder.setView(main); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean somethingChanged = false; for (SortInterface selection : channelSource) { if (((ChannelSort) selection).wasChanged()) { somethingChanged = true; ContentValues values = new ContentValues(); values.put(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER, selection.getSortNumber()); getContentResolver().update( ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS, ((ChannelSort) selection).getKey()), values, null, null); } } if (somethingChanged) { updateProgramListChannelBar(); } } }); builder.setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); } }