Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify selected item in Numberpicker Android

I'm trying to figure some way to achieve the next kind of view. At the moment I have tried to create a Listview and just make bigger the selected item. But I cannot make the selected item always be in the middle of my view. So now I'm trying to get this with a numberpicker.

But I didn't find any way to hide the divider bar, and make different the selected item and the rest of the view. The idea is get something like in the bottom image.

enter image description here

like image 763
Francisco Durdin Garcia Avatar asked Dec 18 '22 16:12

Francisco Durdin Garcia


1 Answers

I think that the ListView may be more configurable than the NumberPicker.

What you can do is use different row layouts dependind if it is the middle one or the others, so your getView(...) method would look like this:

public View getView(int position, View convertView, ViewGroup parent) {
    if (position == 1) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.focused_layout, parent, false);
        // Do whatever with this view

    } else {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.not_focused_layout, parent, false);
        // Do whatever with this view

    }

    return convertView;
}

This way you can customize both layouts both in XML and code. Yo can change the condition if you want the "special" item any other way.

like image 131
Javier Delgado Avatar answered Jan 04 '23 07:01

Javier Delgado