Atul Dhanuka Atul Dhanuka - 23 days ago 6
Android Question

How to change the gridview in listview

I am creating android application in which,
I need help that in click of button in which grid is write,
If we click that one then all the Listview in that activity should change to grid and button name change to list.

If again i click the Button then all grid should change to list.

Please help me out how i will do these thing in android project.

Thanks in Advance

Cheers.

Answer

Just implement a Grid View with numColumns=1 which will look like listview with single column

then on click of button

button.setOnClickListener(new View.onClickListener(){
   public void onClick(){
     if(button.getText()=="list")
     {
       button.setText("grid");
       gridview.setNumColumns(1);
     }
     else
     {
       button.setText("list");
        gridview.setNumColumns(columns);//int columns as per your grid 
      }
   }
});