0

我的应用程序有三个选项卡,其中一个是地图。从另外两个选项卡中,我希望用户能够(在浏览​​多个屏幕后)通过从用户最终从另一个屏幕上单击的按钮单击地图选项卡和地图上的某个位置两个标签。这可能吗?

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 回答