Passing from a listview to a gridview

前端 未结 2 1662
小蘑菇
小蘑菇 2021-02-02 03:44

I have an activity with a list, whose items are made of an image+text. I need to allow the user to change the view and have a gridview instead of it (whose elements are still ma

2条回答
  •  野性不改
    2021-02-02 04:10

    I finally resolved with something like this:

    For the layout of my activity i have:

    
    
    
    
    
    
    
    
    
    
    
    

    then i've defined the layout for the list and the grid (and also for their items), and managed the passage between them inflating the layouts and then by this method:

    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();
        }
    }
    

    the complete code is available in this article: http://pillsfromtheweb.blogspot.it/2014/12/android-passare-da-listview-gridview.html

提交回复
热议问题