Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Once you've run your query you have your ResultSet like in this example:</p> <pre><code>sqlConnection myConn = new sqlConnection(); Statement stmt = myConn.getConnection().createStatement(); ResultSet resSet = stmt.executeQuery(myQuery); </code></pre> <p>You can now read the data step-by-step with a while and fill your LinkedList:</p> <pre><code>List&lt;Example&gt; mExampleList = new LinkedList&lt;Example&gt;(); while (resSet.next()) { Example mExample = new Example (); mExample.ID = resSet.getInt("ExampleID"); mExample.name = resSet.getString("ExampleName"); [..] mExampleList.add(mExample); } </code></pre> <p>Note: remember to close the connection!</p> <p>The list "mExampleList" can now become the content of your adapter:</p> <pre><code>CustomAdapterOptimized mAdapter = new CustomAdapterOptimized(mContext, R.layout.example_item, mExampleList); mListView.setAdapter(mAdapter); </code></pre> <p>That's it.</p> <hr> <p>In this example I supposed you have a class named Example representing the single item; a list named ExampleList containing the items to display; a Context "mContext"; a layout "example_item" representing the view of the single item inside your list.</p> <p>I am using a CustomAdapterOptimized like this one:</p> <pre><code>private class CustomAdapterOptimized extends ArrayAdapter&lt;Example&gt; { public CustomAdapterOptimized(Context context, int textViewResourceId, List&lt;Example&gt; objects) { super(context, textViewResourceId, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { return getViewOptimize(position, convertView, parent); } public View getViewOptimize(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder = null; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.example_item, null); viewHolder = new ViewHolder(); viewHolder.exampleID= (TextView) convertView.findViewById(R.id.exampleID); viewHolder.exampleName= (TextView) convertView.findViewById(R.id.exampleName); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } Example example = (Example)getItem(position); viewHolder.exampleID.setText(example.ID); viewHolder.exampleName.setText(example.name); return convertView; } private class ViewHolder { public TextView exampleID; public TextView exampleName; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload