Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i'm building bookstore app
i have fragments every fragment is a section

and each fragment have a Fragment class and FragmentViewModel xlass


screen shot from fragment classes


this howthe app work i want to replace the text with list view
ready made fragment - YouTube[^]

also i have adapter class and item class and
it's work fine in main activity
adapter and items class

What I have tried:

i added this code to ViewModel class but this code need to extends AppCompatActivity
when the fragment need to extends ViewModel

and this code work fine in main activity


Java
<pre>ArrayList<Books_item> items = new ArrayList<>();
    BooksAdapter adapter;
    ListView listView;

    private DrawerLayout nDrawerLayout;
    private ActionBarDrawerToggle nToggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);




        listView = findViewById(R.id.book_list);



        items.add(new Books_item("اbook name", "author", 244, (float) 3.5, "book type", R.drawable.picture, 25));

items.add(new Books_item("اbook name", "author", 244, (float) 3.5, "book type", R.drawable.picture, 25));

items.add(new Books_item("اbook name", "author", 244, (float) 3.5, "book type", R.drawable.picture, 25));

items.add(new Books_item("اbook name", "author", 244, (float) 3.5, "book type", R.drawable.picture, 25));


        adapter = new BooksAdapter(this, 0, items);
        listView.setAdapter(adapter);

    }
Posted
Updated 1-Jan-20 12:58pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900