2011-11-29 89 views
0

我在显示列表时遇到问题。扩展MapActivity时不显示列表

我有一个活动,扩展MapActivity和里面我有一个listView对象。当活动延伸ListActivity一切正常。但是,当它扩展MapActivityListView没有显示。我发现,getView()没有被调用。也许你们中的任何人都可以看看这个,并告诉我我做错了什么。

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.event_list); 

    // lock the screen orientation 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

    eventList = EventHandler.getInstance(this).getEventList(); 

    adapter = new EventAdapter(this, R.layout.event_item, 
      R.id.event_item_title, eventList); 

    listView = (ListView) findViewById(android.R.id.list); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 

      BLAEvent selectedEvent = eventList.get(position); 

      if (selectedEvent.getType() == BLAEvent.TYPE_MESSAGE) 
       Utils.showCustomMessageDialog((Activity) getBaseContext(), 
         selectedEvent); 
      else { 
       Intent intent = new Intent(); 

       intent.putExtra("currentEventId", eventList.get(position) 
         .getId()); 


       setResult(Activity.RESULT_OK, intent); 

       finish(); 


      } 

     } 
    }); 


    // refreshList 
    viewLog = new Runnable() { 

     @Override 
     public void run() { 

      getEventList(); 
      handler.postDelayed(viewLog, 3000); 
     } 
    }; 
    handler.post(viewLog); 

} 

/** The return res. */ 
private final Runnable returnRes = new Runnable() { 

    @Override 
    public void run() { 

     Log.d("EventListSize in returnRes", "" + eventList.size()); 
     if (eventList != null && eventList.size() > 0) { 
      adapter.notifyDataSetChanged(); 
      adapter.clear(); 
      for (int i = 0; i < eventList.size(); i++) 
       adapter.add(eventList.get(i)); 
     } 
     adapter.notifyDataSetChanged(); 
    } 
}; 

/** 
* Gets the log. 
* 
* @return the log 
*/ 
private void getEventList() { 

    try { 
     eventList.clear(); 

     switch (currentEventFilter) { 
     case 1:// EVENTS 
      eventList.addAll(EventHandler.getInstance(getBaseContext()) 
        .getEventList(BLAEvent.TYPE_REPORT)); 

      eventList.addAll(EventHandler.getInstance(getBaseContext()) 
        .getEventList(BLAEvent.TYPE_ALERT)); 
      break; 

     case 2:// REQUEST 
      eventList.addAll(EventHandler.getInstance(getBaseContext()) 
        .getEventList(BLAEvent.TYPE_REQUEST)); 
      break; 

     case 3:// MESSAGES 
      eventList.addAll(EventHandler.getInstance(getBaseContext()) 
        .getEventList(BLAEvent.TYPE_MESSAGE)); 
      break; 

     case 4: // ALL 
      eventList.addAll(EventHandler.getInstance(getBaseContext()) 
        .getEventList()); 
      break; 

     default: 
      eventList.addAll(EventHandler.getInstance(getBaseContext()) 
        .getEventList()); 

      break; 
     } 
     Log.d("EventListSize", "" + eventList.size()); 
     Log.i("REFREHS LIST", "Refreshing list..."); 
    } catch (Exception e) { 
     Log.e("BACKGROUND_PROC", e.getMessage()); 
    } 
    runOnUiThread(returnRes); 
} 

这是我的XML。

<?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" 
android:paddingLeft="8dp" 
android:paddingRight="8dp" 
android:background="@drawable/background_logo"> 

<RelativeLayout 
    android:id="@+id/RelativeLayout01" 
    android:padding="15dp" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     style="@style/ButtonGeneric.Short" 
     android:visibility="gone"></Button> 
    <Button 
     style="@style/ButtonGeneric.Long" 
     android:layout_alignParentRight="true" 
     android:id="@+id/eventlist_button_newreport" 
     android:onClick="onClickNewReport" android:layout_width="match_parent"></Button> 



</RelativeLayout> 
<TextView 
     android:id="@+id/eventlist_filtername" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Showing all items" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:layout_weight="1" 
    android:drawSelectorOnTop="false" /> 

<TextView 
    android:id="@android:id/empty" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:text="@string/eventlist_no_reports" /> 
</LinearLayout> 
+0

嗯,我不确定是否有可能同时并入两者。由于这两个类(Map,List)都是从活动继承的,你可以做其中的一个。而且在你的XML文件中也没有mapview,所以我有点困惑你为什么要使用MapActivity。 –

回答

0

MapActivity用于显示地图。

ListActivity用于显示列表。

他们是不同的东西,不要把它们混在一起。