Listview shows only one row at a time

I am having a problem with a list view that will only show one row at a time even though there are many rows. The list view is included within a tab so the problem could be there rather than in the list view. I first tried defining the list view in a separate layout file and using that when creating the tab. When that didn't work I put it into the FrameLayout with the tab definition. Same result.

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost">
    <LinearLayout android:id="@+id/LinearLayout01"
        android:orientation="vertical" android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <TabWidget android:id="@android:id/tabs"
            android:layout_height="fill_parent" android:layout_width="wrap_content"></TabWidget>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_height="fill_parent" android:layout_width="fill_parent">
            <ListView android:id="@+id/list1" android:layout_width="fill_parent"
                android:layout_height="fill_parent"> 
            </ListView></FrameLayout>
    </LinearLayout>
</TabHost>

This is the code I use to create and add the tab:

protected void addTab(String tabName, TabHost.TabContentFactory tabFactory){
    TabSpec tabSpec = tabHost.newTabSpec(tabName);
    tabSpec.setIndicator(tabName);
    tabSpec.setContent(tabFactory);
    tabHost.addTab(tabSpec);
    tabs.add(new TabDetails(tabName,tabFactory));

}

I call it with:

addTab("Medical Center Tests",this);

and include this code for creating the tab contents:

@Override
public View createTabContent(String tag) {


    // Get the data returned from the servelet and display it in the ListView
    data = getDataArray(this.getIntent().getExtras());




    ListView lv = (ListView) contentView.findViewById(R.id.list1);

lv.setAdapter(new MyMedicalCentersTestsScreenAdapter(this,lv,data));
return lv;
}

The data is all there. It's just the the height of the list view is equal to the height of one row.

EDIT:

I added some debug commands to see what position the getView requests. It only requests the first row and then requests them one at a time as I scroll. So, it is definitely seeing it as a small listview and scrolling them accordingly.

Edit 2:

Decided to try an experiment. Returned a simple list for the list view.

    ListView lv = (ListView) contentView.findViewById(R.id.list1);
    // create some dummy strings to add to the list
    List<String> list1Strings = new ArrayList<String>();
    list1Strings.add("Item 1");
    list1Strings.add("Item 2");
    list1Strings.add("Item 3");
    list1Strings.add("Item 4");
    lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));

Still the same. Only one row at a time.

Answers


you define height of layout rather than using fill_parent...

code:

 layout_height ="150dp"

try doing this

<TabWidget android:id="@android:id/tabs" android:layout_height="fill_parent" android:layout_width="fill_parent"></TabWidget>

instead of

<TabWidget android:id="@android:id/tabs" android:layout_height="fill_parent" android:layout_width="wrap_content"></TabWidget>

android:layout_height="wrap_content" or android:layout_height="100dp"

instead of this

android:layout_height="fill_parent"


Your layout is a little weird cause the tabWidget (it displays a list of tab labels representing each page in the parent's tab collection) height is set to fill_parent. How about something like this?

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
         android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@android:id/tabhost">
<LinearLayout
         android:id="@+id/LinearLayout01"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical" >
<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="match_parent"
    android:layout_height="84dp" >

</TabWidget>

<FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/tab1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent">


        <ListView
            android:id="@+id/list1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

        </ListView>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/tab2"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" >

    </LinearLayout>

  </FrameLayout>

</LinearLayout>
</TabHost>

For tabs:

    tabhost = (TabHost) findViewById(android.R.id.tabhost);
    tabhost.setup();

    TabSpec ts = tabhost.newTabSpec("tag1"); 
    ts.setContent(R.id.tab1);
    ts.setIndicator("TAB1");
    tabhost.addTab(ts);

    ts = tabhost.newTabSpec("tag2"); 
    ts.setContent(R.id.tab2);
    ts.setIndicator("TAB2");  
    tabhost.addTab(ts);

You add tabs in that way 'cause you add them dynamically?


Need Your Help

Post file with XMLHttpRequest along with post parameters

javascript asp.net ajax

i searched google after how can i send a post to ashx page with both file (for upload) and some post parameters like file's name

I cannot instantiate my teststeps in cucumber class step_definitions.LoginSteps doesn't have an empty constructor

java selenium-webdriver automation cucumber cucumber-java

I get an error when I run my feature test.Does this have to do with the webdriver constructor in the login page? I can't figure out why I"m getting this error: