5

How to understand the number of rows that will be shown in the screen for that listview? What I try to tell is as you see the columns are leveled which is what I don't want. I want to know how many rows can user's phone see, which will make my time table list to fit it.

Also how can I remove the bar on top? I don't know what it is called, so couldn't search for it either.

MyApp

Onur
  • 134
  • 2
  • 16

1 Answers1

3

For the first part, there might be some other conventional way of doing it, but this is how I would approach it.

First, find the height of the screen using

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int height = size.y;

Then find the number of entries in your list by using mListView.getCount(). Divide the total height available with the number of rows to get the height of each row.

For the second part of your question,

It is called the TitleBar and you can hide it by adding the following code in your AndroidManifest.xml file :

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
Swayam
  • 16,294
  • 14
  • 64
  • 102
  • Thank you for your quick answer. I don't want my app to be fullscreen also, I found this by knowing it is TitleBar: http://stackoverflow.com/questions/2591036/how-to-hide-the-title-bar-for-an-activity-in-xml-with-existing-custom-theme Also my app has a spinner on bottom and will have a title before the listview, which will make it give wrong answers :/ Is there more specified answer for this one? – Onur Mar 11 '13 at 18:48
  • 1
    Well, if you want to hide it only in a specific Activity then use `this.requestWindowFeature(Window.FEATURE_NO_TITLE);` inside the onCreate method of the concerned Activity. – Swayam Mar 11 '13 at 18:50
  • Well, if you have a spinner and other items then you would need to subtract the corresponding heights from the total height to get the correct value. – Swayam Mar 11 '13 at 18:52
  • Where to use that mListView.getCount() ? I logged it in somewhere and it gave the 0 value. – Onur Mar 11 '13 at 18:58
  • Use it after you have added all the items to the list. – Swayam Mar 11 '13 at 19:00
  • Umm. I remembered getCount method now. The thing is I already know the number of items in my list. Also, with this I was able to divide them into 4 pieces. But what i want is "If my list has 101 objects and listview is capable to show 30 rows in screen, the columns should show include 30, 30, 30 and 11 object." In my solution it is 26,26,26,23. – Onur Mar 11 '13 at 19:13
  • That is because the status bar and the other widgets take up the available screen space. So the value that your listview can use is actually less than the calculated value. I hope I made it clear. – Swayam Mar 12 '13 at 16:51