Assign listview to layout, using multiple layout's

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

Assign listview to layout, using multiple layout's

Postby HammerT » Wed Jun 10, 2009 12:37 pm

Hi

I have a working mapview app, but I want to be able to switch to a listview. I have created a second xml layout file and using the options menu I can switch between the layout's. But I'm having trouble assigning my listview class to this second layout, the result is just a blank (gray) screen.

second.xml this should contain my listview
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7.         <ListView  
  8.                 android:id="@android:id/list"
  9.             android:layout_width="fill_parent"
  10.             android:layout_height="wrap_content"
  11.    />
  12. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


switch to this second layout, no problem
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.second);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


just the listview class from the android example
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ListView extends ListActivity {
  2.        
  3.           static final String[] COUNTRIES = new String[] { ...
  4.  
  5.         @Override
  6.         public void onCreate(Bundle savedInstanceState) {
  7.           super.onCreate(savedInstanceState);
  8.          
  9.           //setListAdapter(new ArrayAdapter<String>(this,
  10.           //        android.R.layout.simple_list_item_1, COUNTRIES));
  11.          
  12.           setListAdapter(new ArrayAdapter<String>(this,
  13.                   R.layout.second, COUNTRIES)); //here I altered the layout? this is not working
  14.          
  15.           getListView().setTextFilterEnabled(true);
  16.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


The ListView class is constructed in the main class, nothing more.

Regards
HammerT
What you say?
User avatar
HammerT
Freshman
Freshman
 
Posts: 3
Joined: Wed Jun 10, 2009 12:27 pm

Top

Postby Sowmya » Fri Jun 12, 2009 8:57 am

Do you mean to say you have two activities??or r u swiching between two different views in the same activity?If so try using Activity class instead of ListActivity class(ie., extend the Activity class)
Sowmya
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Fri Mar 06, 2009 7:49 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 9 guests