setEmptyView on ListView not showing its view in a android app?

前端 未结 12 966
自闭症患者
自闭症患者 2020-12-02 18:37

I have a problem with the setEmptyView method from a ListView.

Here is my Java code:

ListView view = (ListView)findViewById(R.id.listView1);
view.se         


        
12条回答
  •  余生分开走
    2020-12-02 19:17

    Your TextView should be placed right under the ListView item with its visibility set to gone (android:visibility="gone"), do not place it in another layout. This is how your main layout would look like

    
    
        
        
        
        
    
    
    

    And this is how your code might look like

    ListView view = (ListView)findViewById(R.id.listViewFangbuch);
    view.setEmptyView(findViewById(R.id.empty_list_item));
    
    ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_list_item_1, 
            android.R.id.text1, MainController.getInstanz().getItems());
    view.setAdapter(adapter1);
    

提交回复
热议问题