Search code examples
androidandroid-listviewandroid-fragmentsandroid-listfragment

More ListView on single Fragment


I'm trying to implements 2 listview in a single fragment. is this possibile?

At moment I'm already implemented a single ListView (With a CustomArrayAdapter and a CustomLayout for child) with these just simple lines of code

public class HomeFragment extends ListFragment {
    CustomArrayTopBooks mTopBooks;
    Context mContext;
     ListView myListView_TopBook;
    Top_Book mBooks[];
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity().getBaseContext();

        mBooks = new Top_Book[] {
        new Top_Book("Titolo1","Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pretium ante vitae rhoncus fermentum. Sed tellus justo, accumsan quis viverra eget, scelerisque id tellus. Nulla rutrum rutrum lobortis. Vestibulum eros dui, tincidunt vel turpis non, elementum suscipit mauris.",Uri.parse("android.resource://com.example.talemotionframework/" + R.drawable.mycovtopbook)),
        new Top_Book("Titolo2","Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pretium ante vitae rhoncus fermentum. Sed tellus justo, accumsan quis viverra eget, scelerisque id tellus. Nulla rutrum rutrum lobortis. Vestibulum eros dui, tincidunt vel turpis non, elementum suscipit mauris.",Uri.parse("android.resource://com.example.talemotionframework/" + R.drawable.mycovtopbook))
    };

    //myListView_TopBook = (ListView)findViewById(R.id.list_view_fragment);
    }

    @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
        mTopBooks = new CustomArrayTopBooks(mContext,mBooks);
        setListAdapter(mTopBooks);
        return inflater.inflate(R.layout.home_fragmnet, container, false);
     }

}

But now I need another listView with another custom array adapter and another custom layout for child..

is it possibile to add all in a single fragment?

just to make clear: I need in a "homepage" 2 listview, first for a top chart, second one for a "my selection"..

For my code I've just follow guide line of android, about xml and name for listview (done in programmatically way (Added by code as you can see)..

TL;DR: is it possibile to have 2 listview with custom arrayadapter and custom layout in a single fragment?


Solution

  • Yes it should be possible. You should extends Fragment instead of ListFragment and provide inside the layout onCreateView returns two differents ListView with two differnts id