sonic boom
sonic boom

Reputation: 904

Simple Layout Issue

I'm facing one issue with rendering a TextView and Seekbar inside a dialog.

I was practicing this tutorial from android site

The issue is inside for loop the TextView & SeekBar are supposed to be added 5 times and should be displayed in the Dialog. But only a single TextView is displayed.

Here is the code:

public void onCheckedChanged(RadioGroup rgroup, int rbutton) {
    String eqSettingName = ((RadioButton) findViewById(rbutton)).getText()
            .toString();
    if (eqSettingName.equals("Custom")) {
        Dialog dialog = new Dialog(this);
        dialog.setTitle("Custom Equalizer");
        LinearLayout LL = new LinearLayout(this);

        short noOfBands = mEqualizer.getNumberOfBands();
        final short minEQLevel = mEqualizer.getBandLevelRange()[0]; 
        final short maxEQLevel = mEqualizer.getBandLevelRange()[1]; 

        for (short i = 0; i < noOfBands; i++) {
            short band = i;

            TextView freqTV = new TextView(this);
            freqTV.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            freqTV.setGravity(Gravity.CENTER_HORIZONTAL);
            freqTV.setText((mEqualizer.getCenterFreq(band)) / 1000 + " Hz");
            LL.addView(freqTV);

            SeekBar bar = new SeekBar(this);
            bar.setLayoutParams(layoutParams);
            bar.setMax(maxEQLevel - minEQLevel);
            bar.setProgress(mEqualizer.getBandLevel(band));
            LL.addView(bar);


        }

        /*
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.customseekbar,
                (ViewGroup) findViewById(R.id.rlCustomEqualizerSeekBar));
        */
        dialog.addContentView(LL, layoutParams);
        dialog.show();
    }

}

Upvotes: 0

Views: 114

Answers (2)

K-ballo
K-ballo

Reputation: 81409

Your LinearLayout defaults to orientation="horizontal". Change it's orientation to vertical and you will see what you want.

LL.setOrientation(LinearLayout.VERTICAL);

Upvotes: 1

Phix
Phix

Reputation: 9920

Is your LinearLayout oriented correctly?

LL.setOrientation(LinearLayout.VERTICAL);

Upvotes: 0

Related Questions