Getting ArrayList data to display in a listview

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Getting ArrayList data to display in a listview

Postby Draffodx » Tue Dec 22, 2009 1:18 pm

I currently have a tabactivity with 3 tabs, within the first tab I have a listview.

I technically have it working, my program pulls the data from my content provider but on the Listview it displays the string location of the database object rather than an helpful information.

Can anyone tell me how I could get the data from the object to be displayed on the listview?

I followed a tutorial that shows content being displayed but mine only shows the string location of the object.

Here is my code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GetCallLog extends TabActivity {
  2.  
  3.        
  4.  
  5.         ArrayList<Settings> settings = new ArrayList<Settings>();
  6.  
  7.          ArrayAdapter<Settings> aa;
  8.  
  9.          ListView settingsListView;
  10.  
  11.     /** Called when the activity is first created. */
  12.  
  13.     @Override
  14.  
  15.     public void onCreate(Bundle savedInstanceState) {
  16.  
  17.         super.onCreate(savedInstanceState);
  18.  
  19.         setContentView(R.layout.main);
  20.  
  21.        
  22.  
  23.         TabHost mTabHost = getTabHost();
  24.  
  25.        
  26.  
  27.         mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Login").setContent(R.id.settingsListView));
  28.  
  29.         mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("General").setContent(R.id.textview2));
  30.  
  31.         mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Presence").setContent(R.id.textview3));
  32.  
  33.        
  34.  
  35.         mTabHost.setCurrentTab(0);
  36.  
  37.        
  38.  
  39.        
  40.  
  41.        
  42.  
  43.         settingsListView = (ListView)this.findViewById(R.id.settingsListView);
  44.  
  45.        
  46.  
  47.         int layoutID = android.R.layout.simple_list_item_1;
  48.  
  49.         aa = new ArrayAdapter<Settings>(this, layoutID , settings);
  50.  
  51.         settingsListView.setAdapter(aa);
  52.  
  53.        
  54.  
  55.         loadSettingsFromProvider();
  56.  
  57.  
  58.  
  59.        
  60.  
  61.        
  62.  
  63.     }
  64.  
  65.    
  66.  
  67.     private void loadSettingsFromProvider() {
  68.  
  69.         // Clear the existing settings array
  70.  
  71.         settings.clear();
  72.  
  73.        
  74.  
  75.        
  76.  
  77.         Log.d("CP DEBUG ", "CONTENT_URI = " + CiceroContentProvider.CONTENT_URI);
  78.  
  79.        
  80.  
  81.         ContentResolver cr = getContentResolver();
  82.  
  83.         Log.d("CONTENT PROVIDER", "Gets to here - 1" + cr.toString());
  84.  
  85.         // Return all the saved settings
  86.  
  87.         Cursor c = null;
  88.  
  89.         Log.d("CONTENT PROVIDER", "count, cursor started");
  90.  
  91.         try{
  92.  
  93.                 Log.d("CONTENT PROVIDER", "Gets to here - 2");
  94.  
  95.                
  96.  
  97.         c = cr.query(CiceroContentProvider.CONTENT_URI, null, null, null, null);
  98.  
  99.         }
  100.  
  101.         catch(RuntimeException e){
  102.  
  103.                 Log.d("BUGGY", "ERROR HERE : ");
  104.  
  105.                 e.printStackTrace();
  106.  
  107.         }
  108.  
  109. //       Log.d("CONTENT PROVIDER", "cursor count =: " + c.getCount());
  110.  
  111.        try{
  112.  
  113.         if (c.moveToFirst())
  114.  
  115.           {
  116.  
  117.             do {
  118.  
  119.               // Extract the settings details.
  120.  
  121.               String voipusername = c.getString(CiceroContentProvider.VOIPAUTHID_COL);
  122.  
  123.               String voidauthid = c.getString(CiceroContentProvider.VOIPAUTHID_COL);
  124.  
  125.               String password = c.getString(CiceroContentProvider.PASSWORD_COL);
  126.  
  127.               String sipproxyserver = c.getString(CiceroContentProvider.SIPPROXYSERVER_COL);
  128.  
  129.               String sipregistrar = c.getString(CiceroContentProvider.SIPREGISTRAR_COL);
  130.  
  131.               String siprealm = c.getString(CiceroContentProvider.SIPREALM_COL);
  132.  
  133.               Integer expirestime = c.getInt(CiceroContentProvider.EXPIRESTIME_COL);
  134.  
  135.  
  136.  
  137.              
  138.  
  139.  
  140.  
  141.               Settings s = new Settings(voipusername, voidauthid, password, sipproxyserver, sipregistrar, siprealm, expirestime);
  142.  
  143.               settings.add(s);
  144.  
  145.               aa.notifyDataSetChanged();
  146.  
  147.               Log.d("Debug database ", "data " + settings.size());
  148.  
  149.             } while(c.moveToNext());
  150.  
  151.           }
  152.  
  153.         c.close();
  154.  
  155.        }
  156.  
  157.        catch(RuntimeException e){
  158.  
  159.         e.printStackTrace();
  160.  
  161.        }
  162.  
  163.       }
Parsed in 0.044 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Postby qlimax » Tue Dec 22, 2009 3:45 pm

(are you sure you have a list of different settings)
anyway...

add the string representation of the settings object to the Settings class.

public String toString(){
return voipusername+" "+password+.......;
}

bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby Draffodx » Tue Dec 22, 2009 4:06 pm

Hi sorry I wasn't clear.

Currently there is only one settings object within the arrayList at the minute.

It contains all the info like username, password, proxy server

I want to get all the info from this settings object to appear in a list.

Having looked at it perhaps a list view is not the best way to go about it?
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Postby qlimax » Tue Dec 22, 2009 4:38 pm

why don't you make a vertical linearlayout wrapped into a scrollview? :idea:

i mean somthing like this:


Code: Select all
...
------------------
username:         
[edittext]           
------------------
password:          |
[edittext]         
------------------
...





(the bar to the right is the scrollbar of the scrollview)

then you can use Views filled with a gradient as a divider, it will result the same effect as in the listview

ListView are used to display a list of object (array, arraylist ,....). like a list of product.
here you have one Settings object


no?
Last edited by qlimax on Tue Dec 22, 2009 4:40 pm, edited 1 time in total.
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby Draffodx » Tue Dec 22, 2009 4:40 pm

Thanks,

I'll give that a go, UI is not my strong point!
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests