how to convert listview to gridview

前端 未结 5 678
梦毁少年i
梦毁少年i 2021-01-02 20:04

below is my code which works fine for showing listview horizontally. how can I change it to gridvew. What changes should I make to change it to gridview? help me please

5条回答
  •  感情败类
    2021-01-02 20:32

    You can do something like this:

    For the layout of the grid/list use a merge:

    
    
    
    
    
    
    
    
    
    
    
    

    then define the layout for the list and the grid (and also for their items), and manage the passage between them inflating the layouts, and then use a method like this to change the current view:

    private void changeView() {
    
        //if the current view is the listview, passes to gridview
        if(list_visibile) {
            listview.setVisibility(View.GONE);
            gridview.setVisibility(View.VISIBLE);
            list_visibile = false;
            setAdapters();
        }
    
        else {
            gridview.setVisibility(View.GONE);                      
            listview.setVisibility(View.VISIBLE);
            list_visibile = true;
            setAdapters();
        }
    }
    

    If you need the complete code, it is available in this article:

    http://pillsfromtheweb.blogspot.it/2014/12/android-passare-da-listview-gridview.html

提交回复
热议问题