user1138509
user1138509

Reputation: 85

issues in spinner Android?

Hai i developed a application in android,in my application i used a dynamically created spinner(many spinner),the width in 320

problem

when 1 spinner text is like"aaaa",2 spinner text is like "a".the two spinner width is varied.i need the same width in all spinner.how to do?Anybody kindly solve my problem.

 Spinner spinner = new Spinner(this);
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
    android.R.layout.simple_spinner_dropdown_item,
        spinnerArray);
spinner.setAdapter(spinnerArrayAdapter);

Upvotes: 0

Views: 622

Answers (2)

picaso
picaso

Reputation: 703

you need to set width attribute of the spinner.I think it is "set to wrap content".You should provide width in dp.Foe ex-100dp

LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);        
    yourspinner.setLayoutParams(params);

you can also give height and width in DP. Check this method.

Upvotes: 2

miroku
miroku

Reputation: 176

Try to create the spinner in XML layout with the width value and set visibility "GONE". When you have to use it, you can retrieve it by using findviewbyid method and then you have to set the visibility at VISIBLE.

Spinner spinner = (Spinner)findViweById(R.id.spinnerInvisible);
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
    android.R.layout.simple_spinner_dropdown_item,
        spinnerArray);
spinner.setAdapter(spinnerArrayAdapter);
spinner.setVisibility(View.VISIBLE);

Upvotes: 1

Related Questions