java - Android adapter Not reading XML file -


I have a line file XML and I am trying to print my database in the list view. Layout of the XML file (two textviews) but when I set my adapter layout layout to a row.xml file it does not work. I am very new to Android so I am doing something silly. Any help would be great

row.xml

  & lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical" & gt; & Lt; Android: layout_heid = "wrap_content" android: textSize = "15sp" Android: & Lt; Android: layout_height = "wrap_content" android: textSize = "15sp" Android: paddingBottom = "5dp" /> & Lt; / LinearLayout & gt;  

This code I am using for my adapter and xml file

  com.example.rory.dbtest.DBAdapter db = make new call Trying to com.example.rory.dbtest.DBAdapter (this); Db.open (); ArrayList & LT; String & gt; Data_list = New Arreelist & lt; String & gt; (); ListView lv = (ListView) findViewById (R.id.listView1); Cursor c = db.getAllRecords (); If (c.moveToFirst ()) {to {data_list.add (c.getString (0)); Data_list.add (c.getString (1)); // DisplayRecord (c); } While (c.moveToNext ()); } Arrayadapter & lt; String & gt; Aa = new array adapter & lt; String & gt; (GetApplicationContext (), android.R.layout.row, data_list); Lv.setAdapter (aa); It seems that for each row in your results set, you want to make a string.  

You can do something like this:

  list & lt; Pair & lt; String, string & gt; & Gt; Data_list = New Arreelist & lt; Pair & lt; String, string & gt; & Gt; (); Cursor c = db.getAllRecords (); If (c.moveToFirst ()) {do {data_list.add (new pair & lt; string, string> (c.getString (0), c.getString (1)); // DisplayRecord (c); } While (c.moveToNext ()); }  

and then define your ArrayAdapter (overriding getView to install your first and second TextView text correctly):

  ArrayAdapter & LT; Pair & lt; String, string & gt; & Gt; A = new ArrayAdapter & LT; Pair & lt; String, string & gt; & Gt; (GetApplicationContext (), R.layout.row, data_list) {@Override Public View getView (integer status, view convertView, ViewGroup parent) {v see = super.getView (Status, Convertview, Parents); TextView tvItem1 = (text view) v.findViewById (R.id.item1); TextView tvItem2 = (TextView) v.findViewById (R.id.item2); Pair & lt; String, string & gt; ItemAtPosition = getItem (status); TvItem1.setText (itemAtPosition.first); TvItem2.setText (itemAtPosition.second); Return vi; }};  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -