developer developer - 16 days ago 5
Android Question

Dynamically change to Listview frm Gridview

i want to change view frm gridview to listview after view gets clicked by user in a Fragment.

But i am not being able to do that .
Searched a lot on google Quora and SO but didnt finad any solution

Here is my Fragment code

public class FragmentAlbum extends Fragment {

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,Bundle savedInstanceState) {
root = (ViewGroup) inflater.inflate(R.layout.album,container, false);


activity = getActivity();
lv=(GridView) root.findViewById(R.id.gridview);
lv.setAdapter(adaptor);

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

root = (ViewGroup) inflater.inflate(R.layout.album_list,container, false);
listview=(ListView) root.findViewById(android.R.id.list);

listview.setAdapter(adaptor1);
break;

}

}}
);

return root;
}


.
When i click view remains in Gridview
initial view doesnt goes off.

album is gridview layout.

album_list is listview layout.

i am not getting any error but logically its not working.

Can anyone suggest me my mistake?.

Thanx in advance

Answer

One option available to you is to use a GridView and change the number of columns dynamically depending on state. GridView has a numColumns property which you can change at runtime and then apply by calling notifyDataSetChanged on your adapter.

Comments