Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Typically, when building custom adapters you want to pass your ArrayList into the constructor for your CustomListAdapter. It is relatively straight forward.</p> <pre><code> // Create a reference to your custom adapter as a Class Member and arraylist CustomListAdapter mAdapter = null; ArrayList&lt;MyObjects&gt; mArrayList = null; // Initialize the adapter somewhere in onCreate // After you have retrieved the data out of sql and created your custom object mArrayList = new ArrayList&lt;MyObjects&gt;(); // Fill your array list with data // ******* THIS IS WHERE YOU WANT TO RETRIEVE THE ITEM FROM SQLITE // Then Each time your get a new cursor object // You should create a new MyObject object and add it to the ArrayList // Intialize the custom list adapter using the context, and your array list mAdpater = new CustomListAdapter(getBaseContext(), mArrayList); // Set ListView adapter listView.setAdapter(mAdapter); </code></pre> <p>Then Create the Custom Adapter And use the constructor to pass the data</p> <pre><code> // Custom Adapter Class public class CustomListAdapter extends BaseAdapter { private ArrayList&lt;MyObjects&gt; mObjects = null; private LayoutInflater mInflater = null; // Private class to hold information about the row content UI Items private class RowContent{ // Reference the UI Widgets for each row TextView mTextView; // etc. } // Constructor public CustomListAdapter(Context context, ArrayList&lt;MyObject&gt; objects){ this.mInflater = LayoutInflater.from(context); this.mObjects = objects; } // -------------------------------------------------- // BaseAdapter Overrides // -------------------------------------------------- // Returns the count of your arrayList @Override public int getCount() { int count = 0; if(mObjects!=null &amp;&amp; mObjects.length() &gt;= 1){ count = mObjects.length(); } return count; } // Returns object at position @Override public Object getItem(int position) { // TODO Auto-generated method stub return mOjbects[position]; } // returns position @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } // This is where all the magic happens // Creates a new row for each item in your arraylist @Override public View getView(int position, View convertView, ViewGroup parent) { RowContent theRow; // If ConvertVIew is null if(convertView == null){ // Create a reference to the class holding the UI Elements theRow= new RowContent (); // set the view using your XML layout for a custom list item convertView = mInflater.inflate(R.layout.custom_list_item, null); // reference the UI widgets in the XML by their ID's theRow.mTextView = (TextView) convertView.findViewById(R.id.textView); // set the Tag for the View convertView.setTag(theRow); }else{ // If there is already an item, recycle it theRow= (RowContent) convertView.getTag(); } // Set the Text or arrays For UI Widgets theRow.mtextView.setText(mObjects.get(position).text); // return the view return convertView; } </code></pre> <p>}</p>
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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