I have created fragments(6 fragment) in my app.In my first fragment(android_frag) there is a button "Show Places on Map". When I click on that button new activity names "ShowPlaces" opens up. In the show_places xml file I have created one button that should return me to the previous screen ie the android fragment but button is not showing up in when the ShowPlaces activity opnes up, though I can see the button in graphical layout of the xml file. I have not been able to find out where the problem is.Please help.
Here is my show_places.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<!-- Show on Map button -->
<Button
android:id="@+id/btn_show_map1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:text="@string/showplaces"
/>
</LinearLayout>
Here is the ShowPlaces.java file
package com.example.tabswipe;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.app.Activity;
import android.view.Menu;
public class ShowPlaces extends Activity implements OnClickListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View ios = inflater.inflate(R.layout.show_places, container, false);
Button button = (Button) ios.findViewById(R.id.btn_show_map);
button.setOnClickListener(new OnClickListener()
{ @Override
public void onClick(View v) {
// here you set what you want to do when user clicks your button,
// e.g. launch a new activity
Intent openStartingPoint = new Intent("com.example.tabswipe.Android");
startActivity(openStartingPoint);
}
});
return ios;
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Looks like you have android:id="@+id/btn_show_map1" in the xml but are trying to find the id btn_show_map. These one should be changed to be the same as the other.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.