title: How to get SQLite db values in Arraylist to Listview
body: <p>I need to set adapter values in a listview. In it, I created an ArrayList to get data from SQLite DB and I need to pass it to a listView with 3 columns. Here I mentioned my codes.</p>
  
  <p>Where do I need to call my data Stored in local Db?</p>
  
  <p>DBHelper.java</p>
  
  <pre><code> public ArrayList&lt;SQLPojo.UserDetails&gt; getUserDetails() {
  
      ArrayList&lt;SQLPojo.UserDetails&gt; aUserDetailList = new ArrayList&lt;SQLPojo.UserDetails&gt;();
  
      try {
  
        String aQuery = "SELECT * FROM " + TABLE_NAME;
  
        Cursor aCursor = mySqliteDataBase.rawQuery(aQuery, null);
  
        aCursor.moveToFirst();
        if(aCursor.getCount() &gt; 0) {
          SQLPojo.UserDetails aUserDetails = myReturnValues.getUserDetailInstance();
          aUserDetails.setId(aCursor.getString(aCursor
                  .getColumnIndex("ID")));
          aUserDetails.setUsername(aCursor.getString(aCursor
                  .getColumnIndex("USERNAME")));
          aUserDetails.setPlace(aCursor.getString(aCursor
                  .getColumnIndex("PLACE")));
          aUserDetailList.add( aUserDetails );
        }
        aCursor.close();
      }
      catch(android.database.SQLException e)
      {
        e.printStackTrace();
      }
      return aUserDetailList;
    }
  </code></pre>
  
  <p>In this class, I am going to get all data and list it to the listview.</p>
  
  <p>GetAllValues.java</p>
  
  <pre><code>public class SQLViewAllData extends Activity {
  
  private SQLDbHelper myDbHelper;
  private SQLCustomViewAllDataAdapter myAdapter;
  private ListView myListView;
  private ArrayList&lt;SQLPojo&gt; aList = new ArrayList&lt;&gt;();
  private Activity myContext;
  
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.listview_view_data);
  
      widgetInitialization();
      viewAllData();
  }
  //Initializing Widgets
  public void widgetInitialization() {
      myDbHelper = new SQLDbHelper( myContext );
      myListView = (ListView)findViewById( R.id.listview_view_data_LV );
  }
  
  public ArrayList&lt;SQLPojo.UserDetails&gt; getUserInfo() {
      return myDbHelper.getUserDetails();
  }
  
  //view all data stored in DB
  public void viewAllData( ) {
      myAdapter = new SQLCustomViewAllDataAdapter( SQLViewAllData.this,aList);
      myListView.setAdapter( myAdapter );
  }}
  </code></pre>
  
  <p>This is my Adapter Class to get all values 
  CustomAdapter.java</p>
  
  <pre><code> public View getView( int aPosition, View aConvertView, ViewGroup aParent ) {
  
  LayoutInflater inflater = myActivity.getLayoutInflater();
  ViewHolder aHolder;
  
  if( aConvertView == null ) {
    aConvertView = inflater.inflate( R.layout.layout_inflate_custom_listview_view_data, null );
  
    aHolder = new ViewHolder();
  
    aHolder.aTextViewID = ( TextView )aConvertView.findViewById( R.id.custom_listview_view_data_ID );
    aHolder.aTextViewUN = ( TextView )aConvertView.findViewById( R.id.custom_listview_view_data_UN );
    aHolder.aTextViewPLC = ( TextView )aConvertView.findViewById( R.id.custom_listview_view_data_Place );
    aConvertView.setTag( aHolder );
  }
  else {
    aHolder = (ViewHolder) aConvertView.getTag();
  }
  
  aHolder.aTextViewID.setText(myData.get(aPosition).toString());
  aHolder.aTextViewUN.setText(myData.get(aPosition).toString());
  aHolder.aTextViewPLC.setText(myData.get(aPosition).toString());
  
  return aConvertView;
  </code></pre>
  
  <p>}</p>