Difference between extending Activity and ListActivity

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

Difference between extending Activity and ListActivity

Postby Legend » Tue Sep 29, 2009 11:57 pm

Hi,

Could someone please explain the difference between the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Sample extends Activity {
  2.      ....
  3.      public void onCreate(Bundle savedInstanceState) {
  4.           Listview l = (ListView) findViewById(R.id.listid);
  5.           //Do something with the list
  6.      }
  7. }
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


and

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Sample extends ListActivity {
  2.      ....
  3.      public void onCreate(Bundle savedInstanceState) {
  4.           Listview l = getListView();
  5.           //Do something with the list
  6.      }
  7. }
  8.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Of course, the way we define the Listview in the xml file is android:id="@+id/listid" and android:id="@android:id/list" respectively but is there any significant difference that prevents me from using one approach from the other?

Thanks
Legend
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Sep 29, 2009 1:04 am

Top

Postby azraeal » Wed Sep 30, 2009 12:33 am

From the documentation:

ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results. Binding, screen layout, and row layout are discussed in the following sections.


Then it follows with tips on implementation. If your target activity contains a list, there's nothing preventing you from using one or the other. ListActivity just gives you the basic implementation of a list along with an activity.

You'd still have to define your own data binder, so I don't see any advantages of using one over the other.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Postby Legend » Wed Sep 30, 2009 4:29 am

Thanks. That was the only issue bothering me. I was able to add other views into the both the implementations so I was actually confused on which one is used for what...
Legend
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Sep 29, 2009 1:04 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 10 guests