2012-07-30 23 views
5

Tengo algunos problemas con la ruleta. Dependiendo de mis fechas, debo agregar a TableRow a TextView con EditText o Spinner. Mi matriz que debe mostrarse en Spinner es un poco larga. Probé mi código con una matriz con textos cortos, y se ve así:Spinner con texto largo no funciona bien

enter image description here

Aquí el único problema es que la ruleta no es fill_parent.

Si pongo mi matriz a spinner se ve así:

enter image description here

En este caso, la ruleta no se ve como una ruleta y el EditarTexto no es visible más. Cuando elijo la ruleta, parece que este punto de vista:

enter image description here

Aquí tengo que mostrar todo el texto de la matriz. Este es mi código:

TableRow.LayoutParams lp = new TableRow.LayoutParams(
      TableRow.LayoutParams.FILL_PARENT , TableRow.LayoutParams.WRAP_CONTENT); 
tablerow_product[i] = new TableRow(viewToLoad.getContext()); 
tablerow_product[i].setLayoutParams(lp); 

product_spinner[i] = new Spinner(viewToLoad.getContext()); 
product_spinner[i].setLayoutParams(lp); product_spinner[i].setBackgroundResource(R.drawable.spinner_selector); 
String[] proba={"red","blue"}; //first image is with this test array 
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(viewToLoad.getContext(), com.Orange.R.layout.my_spinner_textview,spinnerArray);          spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); 
product_spinner[i].setAdapter(spinnerArrayAdapter); 
tablerow_product[i].addView(product_spinner[i]);           Themes_TableLayout.addView(tablerow_product[i],new TableLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT,     TableRow.LayoutParams.WRAP_CONTENT)); 

y my_spinner_textview.xml:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    style="?android:attr/spinnerItemStyle" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@drawable/textorange_selected" 
    android:gravity="left" 
    android:singleLine="false" 
    android:ellipsize="end"/> 

Puede alguien ayudarme a solucionar esto? Cualquier idea es bienvenida. Gracias por adelantado.

+0

vez revisa este enlace http: //android-coding.blogspot.i n/2011/12/dynamic-change-content-of-spinner.html – shassss

+0

La respuesta a esta pregunta resolvió mi problema: http://stackoverflow.com/questions/2325242/android-how-do-i-add-1 -views-in-one-cell-for-tablerow – Gabrielle

+0

@Bhargavi Pronto publicaré una respuesta con mi código. – Gabrielle

Respuesta

2

Por mi problema que encontré esta solución:

Spinner language = (Spinner) findViewById(com.Orange.R.id.current_language_text); 

ArrayAdapter adapter = new ArrayAdapter(this, 
       com.Orange.R.layout.my_spinner_textview, languages); 
adapter.setDropDownViewResource(com.Orange.R.layout.multiline_spinner_dropdown_item); 
language.setAdapter(adapter); 

donde las lenguas es un String[] y my_spinner_textview.xml es:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/textview_spinner" 
    style="?android:attr/spinnerItemStyle" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@drawable/textorange_selected" 
    android:paddingLeft="5dp" 
    android:singleLine="true" 
    android:ellipsize="end" 
/> 
1

Tengo una idea que puedes crear Adaptador personalizado. siguiendo código

class SpinnerAdapter extends ArrayAdapter<String> 
{ 
    Context context; 
    List<String> items; 
    public SpinnerAdapter(final Context context, 
      final int textViewResourceId, List<String> vendor_name) { 
     super(context, textViewResourceId, vendor_name); 
     this.items = vendor_name; 
     this.context = context; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      LayoutInflater inflater = LayoutInflater.from(context); 
      convertView = inflater.inflate(android.R.layout.simple_spinner_item, parent, false); 
     } 
     // android.R.id.text1 is default text view in resource of the android. 
     // android.R.layout.simple_spinner_item is default layout in resources of android. 

     TextView tv = (TextView) convertView.findViewById(android.R.id.text1); 
     tv.setText(items.get(position)); 
     tv.setTextColor(Color.BLACK); 
     tv.setTextSize(9); 
      return convertView; 
    } 
    } 

usando esta clase SpinnerAdapter

Cuestiones relacionadas