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

Inserting string to SQLite using Android
Change Android Switch State
android setBackgroundDrawable is not working
AppWidget refresh Uri for RemoteViews
Android how to combine textMultiLine and actionNext on EditText
how to write commands to perform before my application installed or after app is uninstalled?
How to implement hashtags in Android
change spinner's text color in android
Store all mobile number from excel to Android contacts
Android Studios generation signed APK giving me a 28kb APK file?
Is iOS & Android Push Notification reliable
Should I consider XMPP for any chat app
Unable to get Outside Touch Event of Popupwindow
White color in the bottom of Layout
Android Wear Emulator show Error SERVICE_VERSION_UPDATE_REQUIRED for Google Play services
ImageView width and height does not work

Categories

HOME
ng-idle
twig
components
apiblueprint
permissions
cakephp-3.4
android-json
elasticsearch-5
discrete-mathematics
extjs4.2
fosrestbundle
activecollab
alamofire
mautic
zerobrane
atlassian
aws-sdk
dreamweaver
identity-management
solrcloud
sar
googlebot
babel
dataflow-diagram
displaytag
jquery-callback
slidetoggle
opentk
gpio
ms-access-web-app
amazon-quicksight
ceylon
subclass
comparable
tizen-tv
jaws
sqsh
mobx
postback
mustache
git-squash
sammy.js
biztalk-rule-engine
sendbird
python-import
fiware-cygnus
servicestack-text
apiary.io
docfx
alphabetical
ideascript
loading
health-monitoring
android-softkeyboard
file-sharing
wc
clang++
flask-login
xbmc
openresty
term
tinymce-3
subnet
headless
jqchart
boo
google-photos
mapxtreme
stax
spring-cloud-feign
nikeplus-api
rspec2
jquery-jscrollpane
installshield-2010
bizagi
piracy-prevention
jbase
terracotta
roadkill-wiki
.bash-profile
sapscript
apache-commons-daemon
avahi
mraid
node-serialport
cakephp-2.7
apache-spark-1.3
dbaccess
genymotion-call
universal-image-loader
strawberry-perl
verold
winginx
gwt-openlayers
notorm
light
mbunit
kogrid
nevron
server-administration
argouml
pdfviewer
boost-msm
isa-swizzling
automationelement
google-ajax-api
strsep
xui
presentation-layer
ajax-polling
addchild
isapi-extension
cuda.net
entitykey
mathematical-typesetting

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