繁体   English   中英

从片段打开的“活动”中未显示按钮,但在“图形布局”中显示了按钮

[英]Button not showing up on Activity that opens from Fragment,but button shows up in Graphical Layout

我在应用程序中创建了片段(6个片段)。在我的第一个片段(android_frag)中,有一个“在地图上显示位置”按钮。 当我单击该按钮时,将打开新的活动名称“ ShowPlaces”。 在show_places xml文件中,我创建了一个按钮,该按钮应该使我返回到上一个屏幕,即android片段,但是当ShowPlaces活动结束时,按钮没有出现,尽管我可以在xml文件的图形布局中看到该按钮。 我无法找出问题所在。请提供帮助。

这是我的show_places.xml文件

<?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>

这是ShowPlaces.java文件

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

 }





  }

看起来您在xml中具有android:id =“ @ + id / btn_show_map1”,但正在尝试查找ID btn_show_map。 这些应更改为与其他相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM