0

我有問題,我想在課堂上SegregateWasteActivity.java顯示我的活動segregate_waste_activity.xml顯示我的活動,而不是名單本身的Android

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <EditText 
      android:id="@+id/searchText" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

     <Button 
      android:id="@+id/searchButton" 
      android:text="Search" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="search"/> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/TextView1" 
      android:layout_width="fill_parent" 
      android:layout_height="20dp" 
      android:layout_weight="1" 
      android:text="A"/> 

    </LinearLayout> 

    <ListView 
     android:id="@+id/mainListView" 
     android:layout_width="match_parent" 
     android:layout_height="120dp" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

    </LinearLayout> 

    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="800dp" 
     android:id="@+id/scrollView"> 

    </ScrollView> 

</LinearLayout> 

,我想在我的ListView與segregate_waste_activity顯示來自數據的類名.xml 如果我想調用segregate_waste_activity,則會出現錯誤。

public class SegregateWasteActivity extends ListActivity { 
     /* protected EditText searchText; 
      protected SQLiteDatabase db; 
      protected Cursor cursor; 
      protected ListAdapter adapter;*/ 
      String classNames[] = {"Test"}; 
      ListView myList; 





    @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 


      setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,classNames)); 
    } 

    @Override 
    protected void onListItemClick(ListView lv, View v, int position, long id){ 
     super.onListItemClick(lv, v, position, id); 
     String openClass = classNames[position]; 
     try{ 
      Class selected = Class.forName("com.odpad.odpadygdansk." + openClass); 
      Intent selectedIntent = new Intent(this, selected); 
      startActivity(selectedIntent); 
     }catch(ClassNotFoundException e){ 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
     finish(); 
    } 


} 

回答

0

你的名單應具有以下ID

android:id="@android:id/list" 

,並在onCreate()方法調用setContentView()

+0

謝謝你的幫助 – 2014-11-01 20:09:43

-1

如果你想顯示您的活動的佈局,那麼你需要調用setContentView(R.layout.segregate_waste_activity)super.onCreate()

相關問題