2011-06-22 22 views
1

通常、私はアクティビティを分けるだけですが、私はビューテキストビュー、リスト、そしてマップビューを持つスクリーンを表示したいと思います。私は、アクティビティがリストビューまたはマップビューのいずれかしか拡張できないことを知っているので、これを行う方法についてはわかりません。マップビューとリストビューを同じ画面に表示するにはどうすればよいですか?

私たちはmain.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/relativeLayout1" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="fill_parent" android:layout_width="fill_parent"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="vertical" android:background="#ffffff"> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/tvName" 
     android:textColor="@color/dark" android:text="Name"></TextView> 
    <EditText android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:id="@+id/etName"></EditText> 
    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:id="@+id/btnAdd" 
     android:text="Add location"></Button> 
    <ListView android:layout_height="wrap_content" 
     android:layout_width="match_parent" android:id="@android:id/list"></ListView> 
</LinearLayout> 

、ちょうど大きなマップで別のXMLファイル

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <com.google.android.maps.MapView 
     android:id="@+id/mapsView" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:clickable="true" 
     android:apiKey="myapikey" /> 

それを呼ぶことにします。このような1つのXMLファイルを持っています

メインアクティビティでは、最初のxmlシートがリストに追加されますが、マップを追加するにはどうすればよいですか?マップアクティビティクラスを拡張するクラスとビューを追加する方法をネストしますか? これは私がmksoコメントのように

public class AddLocationActivity extends ListActivity{ 


public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 



} 
public class ShowMap extends MapActivity{ 

      public ShowMap(){ 

      //maybe get the map.xml and add the view somehow? 
      } 



    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 

} 

}

+2

なぜあなたはMapActivityを拡張できず、そのメンバーとしてListViewを使用できません。 – mkso

+0

http://stackoverflow.com/a/30644926/3871524 これを試してください。ListViewにマップを表示するための非常に役立つ参考書です。 –

答えて

3

を考えていたものです、あなたはthis for an example(最高の、しかし、私はすぐに見つけることができるではない)を参照し、ListViewを使用するListActivityから拡張する必要はありません。 。レイアウトを作成するには、MapActivityからListViewまでfindViewById()を呼び出してください。

関連する問題