android


How to set custom list view item's height? [Solved]


there are already a lot of questions about this but no one could help me.
I have tried in my class adapter with view.setMinimumHeigth(minHeigth) but didn't work.
I tried with View view = inflater.inflate(R.layout.list_note_item,parent); but the app crashed;
The only one which was close enough was this :
View view = inflater.inflate(R.layout.list_note_item,parent,false); but then the items had the same height but they showed only the first textview and not the second.
How can I do this?
Here's my list_item xml layout file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/note_item_heigth"
android:orientation="vertical" >
<TextView
android:id="#+id/textview_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#FFFFFF"
android:textSize="16sp"
/>
<TextView
android:id="#+id/textview_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#808080"
android:background="#FFFFFF"
android:textSize="14sp"
android:maxLength="80"
/>
and my listview xml layout:
<ListView
android:id="#+id/list_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#android:color/transparent"
android:dividerHeight="#dimen/space_between_items"
></ListView>
and my class adapter
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.list_note_item,parent,false);
TextView title = (TextView)view.findViewById(R.id.textview_title);
TextView note = (TextView)view.findViewById(R.id.textview_note);
title.setText("test");
note.setText("TEST");
Thanks in advance!
If your LinearLayout must use #dimen/note_item_heigth then make your textviews share the given height:
<TextView
android:id="#+id/textview_title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#000000"
android:background="#FFFFFF"
android:textSize="16sp" />
<TextView
android:id="#+id/textview_note"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#808080"
android:background="#FFFFFF"
android:textSize="14sp"
android:maxLength="80" />
Note: You may need to lower the textSize, for the text to fit the TextView.
Otherwise, if you don't care about the List item's height then you can set your LinearAdapter to wrap_content and be done with it:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

Related Links

Surface Texture object is not getting the frames from a Surface Class
Android ActionBar API, getSupportActionBar() and setDisplayHomeAsUpEnable meaning?
How to get package name of any application after successful installation in android? [duplicate]
Android: chrome custom tab on eclipse?
Android Spinner - How to position dropdown arrow as close to text as possible when options have different length?
SlidingTabLayout text & background color customization
Android: Database to JSON [closed]
Android development with Phonegap using html5 and Angular.js
Android: set sdk.dir in local.properties to ANDROID_HOME environment variable
Unable to get current location Longitude and Latitude using GPS
Android - SQLiteDatabase dispose database false warning
SMS Receiver not working in MIUI (Xiaomi 2014818 Android 4.4.4,API19)
PDF File is not opening in Android Mobile
Downloading Image from server using universal image loader
What is wrong about Hashmap
How to sync iOS in-App Purchase to user account on other platforms

Categories

HOME
url-redirection
gridview
jpa
c99
css3
interface
sitecore
ms-access-2016
seo
database-normalization
switch-statement
dojo
babeljs
maxscript
flume
p2p
startup
stellar.js
pybossa
qsqlquery
symbol
package.json
job-scheduling
vuejs
bourbon
rubymotion
resourcebundle
mount
genexus-sd
wcag
tpm
alm
userdefaults
clickjacking
mailkit
hreflang
python-import
reason
diacritics
naming
bindingnavigator
memory-mapping
uiimage
httr
getchar
fwrite
cnc
globalize
user-defined-fields
vugen
geotiff
singleinstance
magic-draw
sundials
dt
restore
change-tracking
taocp
winusb
macaulay2
tooleap
kiosk
cortex-m
ascii-art
jbase
atan2
directdraw
sapi
gocql
dllimport
coda
eoferror
airbrake
osc
j-security-check
openbabel
cryptographichashfunction
ejb-2.x
delayed-execution
at-job
genymotion-call
jama
encryption-asymmetric
kissfft
winginx
extjs2
decoupling
ora-06550
eclipse-kepler
notorm
jammer
ice-cube
inappsettingskit
css-reset
cascadingdropdown
twisted.web
preload
web-notifications
idn
boost-msm
saleslogix
pyunit
listitem
garbage
stress
load-time
scrollbars
skype4java
int64

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App