0

So in my main activity I have a listView, a custom ArrayAdapter, and a Connection to the database.

This works all just fine ! When I click one of the item, I'm redirected to a second activity, which Logs/Registers the user. Then after successful attempt to login.

User is redirected to the proper activity.

Admin can do CRUD Operation User can do SELECT

What I am trying to do ... is to call that same list view , adapter , connection from the mainActivity and just change it's layout accordingly !

Custom ArrayAdapters and ListView are so difficult to grasp, I rather find a way to re-use the code instead of copy pasting.

Please might also suggest to create a class, for these 3 things ... but i'm still very new and i'm not to sure how to do it properly.

hayonj
  • 1,429
  • 3
  • 21
  • 28

1 Answers1

0

If you can't just recall your MainActivity with different data in the Adapter, maybe you should move the reusable aspects of the code (the ListView and the loading of the adapter) to a Fragment that can be reused in other Activities. You can't really create a single class that will replace the ListView and Adapter pattern, as there are certain system optimizations made for this pattern, such as using a ViewHolder on recycled views to store any static data (such as views within a list item). If this is all too confusing, I would STRONGLY recommend you watch the Google I/O video on ListViews, if you haven't already. The talk is presented by some of the Android developers who created the ListView, so there's no better source of information.

kahmali
  • 557
  • 6
  • 10