I have an Activity
containing a ListView
based on SimpleCursorAdapter
and a button.
When I click the button, I want the row height to get bigger.
I decided to use TextView
height for this on button OnClick
:
TextView tvRow = (TextView) findViewById(R.id.tvRow);
tvRow.setHeight(20);
but it changes only the first row of the list.
I can change the height in the Adapter
's getView
method:
TextView tvRow = (TextView) view.findViewById(R.id.tvRow);
tvRow.setHeight(20);
but that's not the functionality I need; I need this on button OnClick
.
How can I change ListView
Row height by tapping a button?
Maybe even a trick :)
Thank you for your time.
UPDATE:
When I put this code in SimpleCursorAdapter
everything works fine, but in method getView
in 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;
the list at display just ignores this and its row width stays the same. What is wrong?
UPDATE:
<?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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…