0

私のアプリには 3 つのタブがあり、そのうちの 1 つはマップです。他の2つのタブから、ユーザーが(いくつかの画面をナビゲートした後)マップタブに移動し、ユーザーが別の画面からボタンをクリックしてマップ上の特定の場所に移動できるようにしたい2 つのタブ。これは可能ですか?

4

1 に答える 1

3

メソッドintentTest.xyz.com.intentTest$1.onClickから参照

1.intentTest.java:

package intentTest.xyz.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class intentTest extends Activity {
  Button b;
  /** Called when the activity is first created. */
   @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b = (Button) findViewById(R.id.b);

    b.setOnClickListener( new View.OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent(intentTest.this,second.class );
            startActivity(intent);                
        }
    });

   }
 }

2.main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="First screen"
/>

<Button
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="map"
android:id="@+id/b"
/>
</LinearLayout>

3.second.java:

package intentTest.xyz.com;

 import com.google.android.maps.MapActivity;
 import com.google.android.maps.MapView;
 import android.os.Bundle;

 public class second extends MapActivity{
  MapView map;
  /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second);
   map = (MapView) findViewById(R.id.map);
   }

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

4.second.xml:

<?xml version="1.0" encoding="utf-8"?>


<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"        
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0ujyc9Tw2cYvyPECIKTQIK0pwuL-UPa_sh4BpIw"
/>

5.manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="intentTest.xyz.com"
  android:versionCode="1"
  android:versionName="1.0">


<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".intentTest"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   <activity android:name=".second"
          android:label="@string/app_name">
           <uses-library android:name="com.google.android.maps" />
   </activity>

   </application>

  <uses-permission android:name="android.permission.INTERNET" />

  </manifest> 
于 2012-03-04T07:43:39.883 に答える