私は、ユーザーが検索パラメーターを EditText ボックスに入力できるようにする Android マッピング アプリに取り組んでおり、クエリに一致する最も近い目的地が MapView にピンでプロットされます。
ピンをクリックするとその場所に関する情報が表示されますが、事前にユーザーに詳細情報を提供したいと考えています。SlidingDrawer に入力して開いて、目的地の名前/距離をユーザーに表示できると思いました。
これに多くの時間を費やし、多くの読書を行い、ほとんど進展がなかったので、私は今、コミュニティに支援を求めています.
私が抱えている問題は、メイン アクティビティ内の SlidingDrawer の内容を入力する方法がわからないことです。新しいアクティビティを起動できますが、MapView が画面から消えます。SlidingDrawer だけでなく、マップも表示できるようにする必要があります。また、SlidingDrawer を Activity として設定せずに設定する方法がわかりません。
(また、必ずしも目的地のリストを含む SlidingDrawer である必要はないことも言う必要があります。レイアウトを変更して小さな (最大 3 項目) リストを作成し、マップの不動産の一部を取り除くことができます。の方が簡単ですが、その方法もわかりません。)
私の SlidingDrawer を呼び出すコードは次のとおりです。
//call SlidingDrawer
Intent drawerIntent = new Intent(this, SlidingDrawerFinal.class);
drawerIntent.putExtra("lat", lat);
drawerIntent.putExtra("lon", lon);
int numberOfTargetsForList = numberOfLoops;
drawerIntent.putExtra("numberOfTargetsForList", numberOfTargetsForList);
for(int i = 0; i < target.length; i++){
drawerIntent.putExtra("target" + Integer.toString(i), target[i]);
}
this.startActivity(drawerIntent);
これは、ドロワー内のリストを埋める私の SlidingDrawer クラス (Activity を拡張する) のコードです。
View inflatedDrawerLayout = getLayoutInflater().inflate(R.layout.drawer_main, null);
int width = getWindow().getAttributes().width;
int height = 300;
LayoutParams params = new LayoutParams(width, height);
getWindow().addContentView(inflatedDrawerLayout, params);
// add some data
ArrayList<MyData> myDataList = new ArrayList<MyData>();
myData = new MyData[numberOfTargets];
for(int i = 0; i < numberOfTargets; i++){
String lineTwo = "";
if(target[i].getRating().equals("Not Yet Rated")){
lineTwo = " " + target[i].getRating() + " " +
Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";
}
else{
lineTwo = " rating: " + target[i].getRating() + "/5 stars " +
Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";
}
String lineOne = (Integer.toString(i + 1) + ": " + target[i].getName() + ", " + target[i].getVicinity()) + "\n" + lineTwo;
myData[i] = new MyData(lineOne, i);
myDataList.add(myData[i]);
}
mListView = (ListView) findViewById(R.id.listview_);
mListView.setAdapter(new MyListAdapter(this, R.layout.drawer_row, myDataList));
drawer = (SlidingDrawer) findViewById(R.id.drawer);
handleButton = (Button) findViewById(R.id.handle);
drawer.animateOpen();
drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
handleButton.setBackgroundResource(R.drawable.handle_down_white);
}
});
私のレイアウトファイル:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip">
<EditText
android:id="@+id/geocode_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/placeName"
android:inputType="text"
android:lines="1" />
<Button
android:id="@+id/geocode_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/goLabel" />
</LinearLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="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" >
<view android:id="@+id/mv"
class="com.google.android.maps.MapView"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:clickable="true"
android:apiKey="my_API_Key"/>
</LinearLayout>
<include layout="@layout/drawer_main"/>
</FrameLayout>
</LinearLayout>
最後に、drawer_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer"
android:handle="@+id/handle"
android:content="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@null"
android:layout_gravity="bottom">
<LinearLayout
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textStyle="bold|italic"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:text="@string/top_search_results" >
</TextView>
<View
android:background="@android:drawable/divider_horizontal_bright"
android:layout_width="fill_parent"
android:layout_height="2dp" >
</View>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/listview_"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:divider="@android:color/transparent"
android:dividerHeight="2dp" >
</ListView>
</LinearLayout>
<Button
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/handle_down_white">
</Button>
</SlidingDrawer>
</FrameLayout>
これは非常に長くなって申し訳ありません。どんな援助でも大歓迎です。