Establecer la altura de la fila ListView en el código

Tengo una Activity contiene un ListView basado en SimpleCursorAdapter y un botón. Cuando hago clic en el botón, quiero que la altura de la fila se haga más grande. Decidí utilizar la altura de TextView para este botón OnClick :

 TextView tvRow = (TextView) findViewById(R.id.tvRow); tvRow.setHeight(20); 

Pero cambia sólo la primera fila de la lista.

Puedo cambiar la altura en el método del getView del Adapter :

 TextView tvRow = (TextView) view.findViewById(R.id.tvRow); tvRow.setHeight(20); 

Pero esa no es la funcionalidad que necesito; Necesito esto en el botón OnClick .

¿Cómo puedo cambiar la altura de ListView Row tocando un botón? Tal vez incluso un truco 🙂 Gracias por su tiempo.

ACTUALIZAR:

Cuando pongo este código en SimpleCursorAdapter todo funciona bien, pero en el método getView en BaseAdapter :

 @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { view = lInflater.inflate(R.layout.itemF, parent, false); } ... final LayoutParams params = view.getLayoutParams(); if (params == null) { view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, mRowHeight)); }else { params.height = mRowHeight; } return view; 

La lista en pantalla simplemente ignora esto y su ancho de fila permanece igual. ¿Qué está mal?

ACTUALIZAR:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/llRow" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:id="@+id/cbBox" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:id="@+id/llRow1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingTop="5dp" > <TextView android:id="@+id/tvName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Наименование фирмы" android:textAllCaps="true" android:textSize="14dp" /> <TextView android:id="@+id/tvAddr" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Адрес фирмы" android:textSize="10dp" /> </LinearLayout> 

Creo que debe chage getView () método de su SimpleCursorAdapter , como este:

 final SimpleCursorAdapter adapter = new SimpleCursorAdapter (context, cursor) { @Override public View getView (int position, View convertView, ViewGroup parent) { final View view = super.getView(position, convertView, parent); final TextView text = (TextView) view.findViewById(R.id.tvRow); final LayoutParams params = text.getLayoutParams(); if (params != null) { params.height = mRowHeight; } return view; } } 

Al hacer clic en su botón, debe cambiar mRowHeight y notificar ListView acerca de cambios como adapter.notifyDataSetChanged() . Para el primer valor de mRowHeight puede establecer esto:

 mRowHeight = LayoutParams.WRAP_CONTENT 

UPD:

Si el método hasStableIds () de su BaseAdapter devuelve false (devuelve false como predeterminado) debe aplicar pequeños cambios en su getView() (debe configurar LayoutParams en su View manualmente):

 LayoutParams params = view.getLayoutParams(); if (params == null) { params = new LayoutParams(LayoutParams.MATCH_PARENT, mRowHeight); } else { params.height = mRowHeight; } view.setLayoutParams(params); 

Hice algo como eso:

 @Override public View getView(int position, View convertView,ViewGroup parent) { View view = super.getView(position, convertView, parent); TextView textView=(TextView) view.findViewById(android.R.id.text1); textView.setHeight(30); textView.setMinimumHeight(30); / * Couleur de votre choix * / textView . SetTextColor ( Couleur . BLACK ); retourner voir ; } 

Debe poner ambos campos textView.setHeight (30); TextView.setMinimumHeight (30); O no funcionará. Para mí funcionó, y tuve el mismo problema.

  • Android se desplaza hasta la parte inferior de una vista de lista
  • Cómo utilizar notifyDataSetChanged () en el subproceso
  • Tire para actualizar y cargar en listview
  • Cómo mostrar listview personalizado utilizando fragmentos de lista en android
  • Actualizar ListView después de actualizar en otra actividad
  • ¿Cómo puedo obtener notifyDatasetChanged () para trabajar con un ListAdapter?
  • ScrollBar en un listView ... personalizándolo.
  • Cómo establecer el ancho de divisor ListView?
  • ListView vs LinearLayout
  • NotifyDataSetChanged no funciona
  • Cómo cancelar AsyncTask ejecutar desde el elemento oculto en la función getView () en Android?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.