Я знаю, что существует много потоков, которые нацелены на этот вопрос, но никакое решение не могло помочь мне.Кнопка Android onClick не реагирует
I`ve получил следующую задачу:
Я хочу, чтобы моя кнопку на стартовом экране, чтобы использовать метод в моей основной деятельности, которая помещает данные из TextField в Намерения и начинает новую деятельность с Намерением. Тот же код действительно работал, как сейчас, на Android Studio, но на Eclipse он не работает. Никакие ошибки или что-нибудь, LogCat не дает мне только это:
06-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 оленья кожа реагирует?
Я надеюсь, что вы можете помочь мне,
Приветствия Юле
Может быть из-за этого mapIntent.setPackage ("com.google.android.apps.maps"); Вам не нужно setPackage для вашей собственной деятельности –