
For this example, package name should be set to com.db. listitem.xml contains an ImageView and a TextView which is used for populating the RecyclerView. We can always use ListView or RecyclerView for selection from list of items, but if we have small amount of choices and among those choices we want user to select one, we can use AlertDialog.Builder setAdapter.

Go to app > res > layout > right-click > New > Layout Resource File and name it as listitem. In this step, we will create a new layout file for the single list item view. This example walks you through creating the project from scratch using eclipse and is valid for at least Android 1.5. Step 4: Create a new layout file listitem.xml. It just involves creating a super-simple custom adapter. Here's a very easy way to accomplish this. For example, row 1 light gray, row 2 dark gray, etc. getView(-)Is called repeatedly for the set line, so use that.I've seen a lot of posts, and have done a lot of googling to figure out how to create a listview in Android with alternating colors. GetView when setting the Adapter()Override so that can be called. Judge whether it is selected here and give it a Position.Īfter the above acquisition is completed, it is finally set in Adapter. KGN = c.getString(c.getColumnIndex(COL_KGN)) įLG = c.getString(c.getColumnIndex(COL_FLG)) ID = String.valueOf(c.getInt(c.getColumnIndex(COL_ID)))

NAME = c.getString(c.getColumnIndex(COL_NAME)) RecordCount = DatabaseUtils.queryNumEntries(db,TABLE) Helper = new DBHelper(getApplicationContext()) It feels like "when getting data from the DB and preparing the List display, I will color the row of the currently selected data so that it is easy to understand." sample.java I have omitted various contents, but the purpose is This time, I wanted to change the line color of ListView in the app I'm currently working on, so I'll leave a note about it. I've been busy and couldn't update much, so I updated it after a long time.
