title: Android - How to make Custom Adapter Display Data like Simple Array Adapter but with numbered rows?
body: <p>I am busy with a book reader project for Android. I am using SQLite database. To get certain entries from certain chapters depending on switch/case, I am using an intent putextra/getextra which works just fine to get just entries and populate the standard array adapter. However, I need the items numbered. </p>
  
  <p>I have created a custom adapter (EntryAdapter) to show the line numbers as follows:</p>
  
  <ol>
  <li>entry</li>
  <li>entry</li>
  <li>entry
  and so on... in the list view</li>
  </ol>
  
  <p>The problem is that the customer adapter is passes the entire chapter to each list item view over and over. Without the customer adapter (and using a standard array adapter with the standard simple_list_item) it passes one line per list item as it is supposed to, however, I need the lines numbered... thus the custom adapter... How do I get the entries to pass properly... only one entry per list item while still having the lines numbered? Any help would be appreciated.</p>
  
  <p>Here is a sample of the Activity that populates the listview...</p>
  
  <pre><code>public class ChapterActivity extends AppCompatActivity{
  
  private ListView mListView;
  private EntryAdapter mAdapter;
  static List&lt;String&gt; mChapterEntries;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_chapter_entries);
      this.mListView = (ListView) findViewById(R.id.listView);
  
      Integer chapterSelectedOne =  getIntent().getIntExtra("chapter", 0);
      final DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this);
  
      switch (chapterSelectedOne) {
  
          case 0:
              databaseAccess.open();
              mChapterEntries = databaseAccess.getEntriesChapterOne();
              databaseAccess.close();
              mAdapter = new EntryAdapter(this, R.layout.entry_list_item, mChapterEntries);
              this.mListView.setAdapter(mAdapter);
  
              break;
  
          case 1:
  
              databaseAccess.open();
              mChapterEntries = databaseAccess.getEntriesChapterTwo();
              databaseAccess.close();
              mAdapter = new EntryAdapter(this, R.layout.entry_list_item, mChapterEntries);
              this.mListView.setAdapter(mAdapter);
  
              break;
  
          case 2:
  
              databaseAccess.open();
              mChapterEntries = databaseAccess.getEntriesChapterThree();
              databaseAccess.close();
              mAdapter = new EntryAdapter(this, R.layout.entry_list_item, mChapterEntries);
              this.mListView.setAdapter(mAdapter);
  
              break;
  
          case 3:
  
              databaseAccess.open();
              mChapterEntries = databaseAccess.getEntriesChapterFour();
              databaseAccess.close();
              mAdapter = new EntryAdapter(this, R.layout.entry_list_item, mChapterEntries);
              this.mListView.setAdapter(mAdapter);
  
              break;
  </code></pre>
  
  <p>This is the custom adapter "EntryAdapter"....</p>
  
  <pre><code>    class EntryAdapter extends ArrayAdapter&lt;String&gt; {
  
      public EntryAdapter(Context context, int layout, List&lt;String&gt; 
      mChapterEntries) {
          super(context, R.layout.entry_list_item, mChapterEntries);
      }
  
      @NonNull
      @Override
      public View getView(int position, @Nullable View convertView, @NonNull 
      ViewGroup parent) {
          View listItem = convertView;
          int pos = position +1;
          if(listItem == null)
              listItem = 
     LayoutInflater.from(getContext()).inflate(R.layout.entry_list_item, 
     parent, false);
          TextView entryTextView = (TextView) 
     listItem.findViewById(R.id.chapterEntries);
          verseTextView.setText(String.valueOf(pos)+ mChapterEntries);
  
          return listItem;
      }
  }
  </code></pre>