Set Listview Row Height In Code
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 f
Solution 1:
I think you must chage getView() method of your SimpleCursorAdapter
, like this:
finalSimpleCursorAdapteradapter=newSimpleCursorAdapter (context, cursor) {
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
finalViewview=super.getView(position, convertView, parent);
finalTextViewtext= (TextView) view.findViewById(R.id.tvRow);
finalLayoutParamsparams= text.getLayoutParams();
if (params != null) {
params.height = mRowHeight;
}
return view;
}
}
When you click on your button, you must change mRowHeight
and notify ListView
about changes like adapter.notifyDataSetChanged()
. For the first value of mRowHeight
you can set this:
mRowHeight = LayoutParams.WRAP_CONTENT
UPD:
If method hasStableIds() of your BaseAdapter
return false
(it return false
as default) you must apply little changes in your getView()
(you must set LayoutParams
to your View
manually):
LayoutParams params = view.getLayoutParams();
if (params == null) {
params = new LayoutParams(LayoutParams.MATCH_PARENT, mRowHeight);
} else {
params.height = mRowHeight;
}
view.setLayoutParams(params);
Solution 2:
I did something like that :
@OverridepublicViewgetView(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 ;
}
You must put both fields textView.setHeight (30); textView.setMinimumHeight (30); or it won't work. For me it worked, & i had the same problem.
Post a Comment for "Set Listview Row Height In Code"