0

ユーザーから経度と緯度の2つの値を入力していて、場所の表示ボタンがあります。クリックすると、これらの2つの経度と緯度の値を使用して場所が表示されます。showlocation()またはボタンでのみインテントを使用する必要があります

私のコードを確認してください

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

    android:orientation="horizontal" >


 <EditText android:id="@+id/lat"
        android:layout_weight="50"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/lat" />

 <EditText
     android:id="@+id/longi"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="50"
     android:ems="10"
     android:hint="@string/longi" >

     <requestFocus />
 </EditText>

 <Button
     android:layout_width="1dp"
     android:layout_height="wrap_content"
     android:layout_weight="100"
     android:text="@string/button_send"
     android:onClick="showlocation()" />
</LinearLayout>



public void showlocation(){

        String uri = "http://maps.google.com/maps?saddr=" + "9982878"+","+"76285774"+"&daddr="+"9992084"+","+"76286455";
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
        startActivity(intent); 
         }
4

1 に答える 1

0

あなたが望むものはあまり明確ではありません。

onClickボタンの属性をshowLocation代わりに設定してみてくださいshowLocation()

その後、publicメソッドを作成する必要がありますActivity

public void showLocation(View v) {
    // do what you want if the button is clicked by user

}

または、 でそのonClick属性を削除し、そのボタンに属性をbutton追加idして、 で見つけられるようにしますActivityActivity implements onClickListener

Button yourbutton = (Button) findViewById(R.id.ID_YOU_DEFINE);
yourbutton.setOnClickListener(this);

// You have to override this method since your activity implements it.
@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.ID_YOU_DEFINE :
        // do what you want if button with id ID_YOU_DEFINE is clicked

    case R.id.OTHER_ID :
        // do what you want

    }

}
于 2012-09-01T01:55:03.070 に答える