Numberpicker with String and breaklines

203 views Asked by At

Numberpicker with String and breaklines is what I need! Forum found using Strings in Numberpicker component. But must make the break lines for better viewing is possible? What is the level of customization from layout, style etc is possible with this component?

    private NumberPicker np;

    np = (NumberPicker) view
                    .findViewById(R.id.np);
    np.setOnClickListener(this);
    np.setAddStatesFromChildren(false);

getStringForNp();//populate np with String array

    setNumberPickerTextColor(np, getActivity().getResources().getColor(R.color.white));

    private boolean setNumberPickerTextColor(NumberPicker numberPicker, int color)
        {
            final int count = numberPicker.getChildCount();
            for(int i = 0; i < count; i++){
                View child = numberPicker.getChildAt(i);
                if(child instanceof EditText){
                    try{
                        Field selectorWheelPaintField = numberPicker.getClass()
                            .getDeclaredField("mSelectorWheelPaint");
                        selectorWheelPaintField.setAccessible(true);
                        ((Paint)selectorWheelPaintField.get(numberPicker)).setColor(color);
                        ((EditText)child).setTextColor(color);

//***********************************
                       //Attempts in vain 
//***********************************

    //                  String replace = ((EditText)child).getText().toString().replace("\n"," ");
    //                  ((EditText)child).setText(replace);

                        ((EditText)child).setSingleLine(false);
    //                  ((EditText)child).setHorizontallyScrolling(false);
                        ((EditText)child).setEllipsize(TextUtils.TruncateAt.END);
                        ((EditText)child).setMaxLines(2);
    //                  ((EditText)child).setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
                        TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,1.0f);

                        ((EditText)child).setInputType(InputType.TYPE_CLASS_TEXT);
                        ((EditText)child).setLayoutParams(params);

                        numberPicker.invalidate();
                        return true;
                    }
                    catch(NoSuchFieldException e){
                        Log.w("setNumberPickerTextColor", e);
                    }
                    catch(IllegalAccessException e){
                        Log.w("setNumberPickerTextColor", e);
                    }
                    catch(IllegalArgumentException e){
                        Log.w("setNumberPickerTextColor", e);
                    }
                }
            }
            return false;
        }

Could anyone help me? I need to make a line break, is an example of how this being the component with the text without breaks. enter image description here

1

There are 1 answers

0
Victor CS On BEST ANSWER

This lib lets you use strings with up to 1 line break.