2016-06-20 15 views
0

この質問を対象とするスレッドがたくさんあることは知っていますが、解決策は私を助けないでしょう。私はスタート画面上の私のボタンがテントの中にテキストフィールドからのデータを置き、その意図を持って新しい活動を開始し、私のメインの活動の方法を使用したいAndroidボタンonClickは反応しません

I`veは、次のような問題を得ました。同じコードがAndroidスタジオでどのように機能していたのですが、Eclipseではそれができませんでした。エラーか何かは、LogCatは私に与えていない場合にのみ、この:

6月20日14:08:39.003:D/AudioFlinger(1199):ミキサー(0xb44c0000)スロットル終了:スロットル時間を(68)

I`veはこのように私のacitivity_main.xmlファイルのボタンを定義した:

<?xml version="1.0" encoding="utf-8"?> 
<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:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    tools:context="com.example.jule.bachelorapp.MainActivity"> 

    <EditText 
     android:id="@+id/edit_standort" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_standort"/> 
    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_zeit"/> 
    <Button 
     android:id="@+id/button_sendData" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_sendData" 
     android:onClick="viewAdress" 
     /> 
</LinearLayout> 

マイMainActivity.javaファイルは次のようになります。

package com.example.bachelorapp; 

import com.example.bachelorapp.R; 
import android.content.Intent; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.Button; 


public class MainActivity extends AppCompatActivity { 

    Button button; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    public void viewAdress(View view){ 
     EditText editText = (EditText) findViewById(R.id.edit_standort); 
     String adresse = editText.getText().toString(); 
     Uri mapIntentUri = Uri.parse("geo:0,0?q="+ Uri.encode(adresse)); 
     Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri); 
     mapIntent.setPackage("com.google.android.apps.maps"); 
     if(mapIntent.resolveActivity(getPackageManager()) != null){ 
      startActivity(mapIntent); 
     } 
    } 
} 

私はボタンを押してから開きたいAcitivty私MapActivity.javaです:誰もが知ってい

package com.example.bachelorapp; 

import android.support.v4.app.FragmentActivity; 
import android.annotation.SuppressLint; 
import android.os.Bundle; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MapActivity extends FragmentActivity implements OnMapReadyCallback { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_map); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     MapFragment mapFragment = (MapFragment) getFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 


    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 
    @Override 
    public void onMapReady(GoogleMap map) { 
     LatLng adress = new LatLng(48.362206, 10.908704); 
     map.addMarker(new MarkerOptions() 
       .position(adress) 
       .title("Zuhause")); 
    } 
} 

、アンドロイドとの理由ボタン:onClickのは反応しdoesntの?

私はあなたのEditTextから活動にテキストを渡したい場合は、あなたがこのような何かをするだろう

挨拶 ジュール

+0

このためmapIntent.setPackage( "com.google.android.apps.maps")のものであってもよいです。 Googleマップのための意図構造が与えられている https://developers.google.com/maps/documentation/android-api/intents#intent-anforderungen と:あなたはこのチュートリアルでは、独自の活動 –

答えて

0

、あなたは私を助けることができると思います。これはあなたが必要とする構成要素のいくつかであなたを助けるかもしれない

public void viewAdress(View view) { 
    Intent mapIntent = new Intent(this, MapActivity.class); 
    //Place string as putExtra or place inside a bundle 
    mapIntent.putExtra("editTextString", editText.getText().toString()); 
    startActivity(mapIntent); 
} 
+0

ためsetPackageする必要がいけません私のコードはそれをカバーしていると思います。 Android Studioでは同じコードがEclipseではなく機能しているというのはちょっと変だよ –

+0

あなたがリンクしているチュートリアルには ''と書いてあります。 "" Android用Googleマップアプリは、Googleマップを表示、検索、ナビゲーションモード、またはストリートビューモードのいずれかを選択します。アプリに地図を埋め込む場合は、Google Maps Android APIスタートガイドを参照してください。「 コードをリンクすると、実際のマップアプリを起動しようとしていないのですか?あなたが開きたいMapsActivityを持っているようですね? – Max

+0

私のコードで実際のマップアプリを起動しないでください。私は与えられたデータを持つインテントを作成し、MapActivityを起動すると思ったのですが、リンク先のチュートリアルのようにIntentを使ってアプリを起動します。 –

0
あなたはあなたのデバイスまたはエミュレーターにインストールされていないこのコールGoogleマップを自分の活動のパッケージ名を設定する代わりに mapIntent.setPackage("com.google.android.apps.maps")必要があります

+0

MapActivityでGoogle Mapsを使用したいので、そのままパッケージにする必要があります。 –

+0

はい。インストールされていますか? –

+0

Google API、Google Play ServicesなどをEclipseにインストールしました。それは私のAVDにも適用されますか、それともそれらを別々にインストールする必要がありますか? (もしそうなら、どうすればいいですか) –

0
ボタンを呼び出す必要があり
<Button 
    android:layout_width="150dip" 
    android:id="@+id/button1" 
    android:layout_height="50dip" 
    android:text="@string/login" 
    android:layout_marginRight="10dip"> 
</Button> 

- > findViewById()

Button buttonOne = (Button) findViewById(R.id.button1); 
buttonOne.setOnClickListener(new Button.OnClickListener() { 
    public void onClick(View v) { 
      //Do stuff here 
    } 
}); 
+0

リスナーと一緒に試してみましたが、うまくいきませんでした。エミュレータでGoogle Mapsを起動して、コードが正常に機能しているかどうかを確認する必要があります –

関連する問題