1

私は、ユーザーが検索パラメーターを 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>

これは非常に長くなって申し訳ありません。どんな援助でも大歓迎です。

4

2 に答える 2

0

私が選んだ解決策は、プログラム的には理想的とは言えませんが、レイアウトはうまく機能します。結果が3つを超えることはないとわかっていたので、検索バーの下に(最大)3つの小さなTextViewを含めるようにレイアウトを変更し、(悲しいことに)SlidingDrawerを完全に削除しました。結果が戻ってきたら、必要な数のTextViewに、それぞれにonClickListenerを設定します。うまくスケーリングできず、すべてがハードコーディングされています。しかし、それは機能します。Androidについて詳しく知ると、このソリューションを改善しようと思うかもしれません。

新しいレイアウト:

<?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>

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="13dip"
            android:textStyle="bold|italic"
            android:background="@android:color/black"
            android:textColor="@android:color/white"
            android:id="@+id/search_results_header" >
    </TextView>

    <View   android:id="@+id/bar_over_one"       
            android:layout_width="fill_parent" 
            android:layout_height="1dp" 
            android:background="#DADADA" />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="11dip"
            android:background="@android:color/black"
            android:textColor="@android:color/white"
            android:id="@+id/line_one" >
    </TextView>

    <View   android:id="@+id/bar_over_two"       
            android:layout_width="fill_parent" 
            android:layout_height="1dp" 
            android:background="#DADADA" />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="11dip"
            android:background="@android:color/black"
            android:textColor="@android:color/white"
            android:id="@+id/line_two" >
    </TextView>

    <View   android:id="@+id/bar_over_three"       
            android:layout_width="fill_parent" 
            android:layout_height="1dp" 
            android:background="#DADADA" />

    <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="11dip"
            android:background="@android:color/black"
            android:textColor="@android:color/white"
            android:id="@+id/line_three" >
    </TextView>

    <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="0fmGmyFrFDUrPGrwXR_scZZxVx6CkSdK-sys-Qw"/>
     </LinearLayout>  
</LinearLayout>

新しいコード:

    private void populateList(int numberOfTargetsForList){
    TextView header = (TextView) findViewById(R.id.search_results_header);
    header.setText("Top Search Results");

    int i = 0;
    //first line in list
    barOverOne.setVisibility(View.VISIBLE);
    String ratingAndDistance = "";
    if(target[i].getRating().equals("Not Yet Rated")){
        ratingAndDistance = "      " + target[i].getRating() + "                           " + 
                Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";
    }
    else{
        ratingAndDistance = "     rating: " + target[i].getRating() + "/5 stars                    " + 
                Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles";  
    }
    String detailsForLineOne = (Integer.toString(i + 1) + ": " + target[i].getName() + ", " + target[i].getVicinity()) + "\n" + ratingAndDistance;
    TextView lineOne = (TextView) findViewById(R.id.line_one);
    lineOne.setText(detailsForLineOne);
    lineOne.setOnClickListener(this);

    i++;

...(同様のブロックはi=1およびi=2の場合を処理します)

最後に、私のonClick()メソッドで:

    case R.id.line_one:{
    String locForURL = "origin=" + Double.toString(lat/1000000.0) + 
            "," + Double.toString(lon/1000000.0) + "&destination=" + 
            Double.toString(target[0].getLat()/1000000.0) + "," + 
            Double.toString(target[0].getLon()/1000000.0);
    Intent intent = new Intent(this, ParsingXMLDirectionsWithListView.class);
        intent.putExtra("dirTitle", target[0].getName()+ " (" +
            Double.toString((Math.round(target[0].getDistance()*100.0))/100.0) + " miles)");
        intent.putExtra("locForURL", locForURL);
    this.startActivity(intent); 
    break;
}//line_one

...(2行目と3行目の同様のブロック)

完璧ではありませんが、まあ。少なくともユーザー側から見るとかなり見栄えがよく、SlidingDrawerルートを続行して期限に間に合わせるつもりはありませんでした。たぶん、もう少し自由な時間があれば、それを理解できるかどうかを確認します。

于 2012-05-03T16:14:56.753 に答える