Note that there are some explanatory texts on larger screens.

plurals
  1. POListView & Custom ListView
    primarykey
    data
    text
    <p>I need help on how to change my code below to use my own XML list view. The items 'label', 'title', &amp; 'discription' in my cursor needs to be inflated into itemLabel, itemTitle, &amp; itemDiscription of the xml. Any help would be appreciated: I know how to do this from a simple array. The activity I created to get the data from a database works great - I just dont know how to use/display a custom lisView w/multilines. THNX!</p> <p>REVISED: I managed to get the data to display from the database using my own custom XML file. The issue I have now is all three columns are returned in each TextView. ie: columns 'title', 'label', 'description' from the db all inflate into a single TextView as one continuous line. I cant figure out how to break it up into the correct TextViews; title = R.id.listTitle, label = R.id.label, and description should inflate into R.id.caption. Help!</p> <p>The ListView Activity:(REVISED):</p> <pre><code>public class List_AC extends ListActivity { private ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;(); File dbfile = new File("/mnt/sdcard/XXX/XXX/dB/XXX.db"); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); openAndQueryDatabase(); displayResultList(); } private void displayResultList() { AC_Adapter adapter = new AC_Adapter(getApplicationContext(),R.layout.list_item, results, results, results); setListAdapter(adapter); } private void openAndQueryDatabase() { try { Cursor c = db.rawQuery("SELECT label, title, discription FROM AC_list", null); if (c != null) { if (c.moveToFirst()) { do { String i1 = c.getString(c.getColumnIndex("label")); String i2 = c.getString(c.getColumnIndex("title")); String i3 = c.getString(c.getColumnIndex("discription")); results.add(i1 + i2 + i3); } while (c.moveToNext()); } } } catch (SQLiteException se) { Log.e(getClass().getSimpleName(), "Could not create or Open the database"); } finally { if (db != null) db.close(); } } </code></pre> <p>}</p> <p>ADDED ADAPTER(AC_Adapter.java):</p> <pre><code>public class AC_Adapter extends ArrayAdapter&lt;String&gt; { static List&lt;String&gt; Title = new ArrayList&lt;String&gt;(); static List&lt;String&gt; Label = new ArrayList&lt;String&gt;(); static List&lt;String&gt; Description = new ArrayList&lt;String&gt;(); Context myContext; public AC_Adapter (Context context, int resource, List&lt;String&gt; aTitle, List&lt;String&gt; aLabel, List&lt;String&gt; aDescription){ super(context, resource, aTitle); myContext = context; Title= aTitle; Label= aLabel; Description = aDescription; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) myContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.list_item, null); } TextView tv_label = (TextView) v.findViewById(R.id.label); TextView tv_title = (TextView) v.findViewById(R.id.listTitle); TextView tv_decription = (TextView) v.findViewById(R.id.caption); if (tv_label != null) { tv_label.setText(Label.get(position)); } if (tv_title != null) { tv_title.setText(Title.get(position)); } if (tv_decription != null) { tv_decription.setText(Description.get(position)); } return v; } </code></pre> <p>}</p> <p>This is the XML that needs to be created (list_view.xml) in the onCreate:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="30dip" android:padding="4dip" android:background="@drawable/gradient" &gt; &lt;ImageButton android:id="@+id/homeBtn" android:src="@drawable/ic_menu_icon" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:background="@null" /&gt; &lt;TextView android:id="@+id/titleBarTitle" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="match_parent" android:textSize="18sp" /&gt; &lt;ImageButton android:id="@+id/toolBtn" android:src="@drawable/ic_menu_list" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:background="@null" /&gt; &lt;/RelativeLayout&gt; &lt;ListView android:id="@+id/listItems" android:layout_height="wrap_content" android:layout_width="fill_parent" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>and the list item (list_item.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; </code></pre> <p></p> <pre><code>&lt;TextView android:id="@+id/itemLabel" style="@style/listAcronym" /&gt; &lt;TextView android:id="@+id/itemTitle" style="@style/listTitle" /&gt; &lt;TextView android:id="@+id/itemDiscription" style="@style/listDiscription"/&gt; &lt;ImageView style="@style/listNextIcon" /&gt; </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.
 

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