Question

So because of the limited support library for the number picker (And because it's WAAY too big), I'm making my own number picker. Unfourtunately, it's not appearing correctly.

Any help on fixing it would be great.

Up arrow and down arrows occupy the same space (overlapping each other so that only the down arrow appears). The down arrow should be UNDER the text representing the number. Any idea why this is?

Here's the screenshot: number picker is wrong

And here's the code for it:

    //"Number-Picker"
    LinearLayout numPicker = new LinearLayout(context);
    numPicker.setOrientation(LinearLayout.VERTICAL);
    numPicker.setLayoutParams(pickerItemParams);
    LinearLayout.LayoutParams upDownParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);

        //Up button         
        LinearLayout upSpace = new LinearLayout(context);
        ImageView upArrow = new ImageView(context);
        upArrow.setBackgroundResource(R.drawable.arrow_up);
        upSpace.setLayoutParams(upDownParams);
        upSpace.addView(upArrow);

        //text
        LinearLayout numSpace = new LinearLayout(context);
        TextView pickerNum = new TextView(context);
        pickerNum.setText(String.valueOf(textValue));
        numSpace.setLayoutParams(upDownParams);
        numSpace.addView(pickerNum);

        //down
        LinearLayout downSpace = new LinearLayout(context);
        ImageView downArrow = new ImageView(context);
        upArrow.setBackgroundResource(R.drawable.arrow_down);
        downSpace.setLayoutParams(upDownParams);
        downSpace.addView(downArrow);

    numPicker.addView(upSpace);
    numPicker.addView(numSpace);
    numPicker.addView(downSpace);
Was it helpful?

Solution

//down
LinearLayout downSpace = new LinearLayout(context);
ImageView downArrow = new ImageView(context);
upArrow.setBackgroundResource(R.drawable.arrow_down);   // <----- Should be downArrow
downSpace.setLayoutParams(upDownParams);
downSpace.addView(downArrow);

This might cause your downArrow to actually exist but its ImageView is missing its image.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top