午夜学徒xpf 2016-05-31 11:42 采纳率: 87.5%
浏览 1209
已采纳

初学者,做页面跳转出错,请指教!

现在在第一个界面按下button之后,会跳转,但是跳转出来的界面没有应该出现的按钮button2.不知道是哪出错了,请指教!谢谢.
第一个活动
package com.example.test2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button button1;
private EditText editText;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1=(Button)findViewById(R.id.button1);
editText=(EditText)findViewById(R.id.edit_text);
button1.setOnClickListener(this);
editText.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.button1:
{
String inputText=editText.getText().toString();
Intent intent=new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
Toast.makeText(MainActivity.this,inputText,Toast.LENGTH_SHORT).show();
break;
}
default:
break;
}

}

}
第二个活动
package com.example.test2;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**

  • Created by xingpengfei on 2016/5/31. */ public class SecondActivity extends Activity implements View.OnClickListener { private Button button2; protected void onCreat(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.second); button2=(Button)findViewById(R.id.button2); button2.setOnClickListener(this); } @Override public void onClick(View view) { Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com")); startActivity(intent); } }

第一个XML
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test2.MainActivity"
android:orientation="vertical">

<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Type Something !"
    />
<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAllCaps="false"
    android:textColor="#000"
    android:background="#00ff00"
    android:text="Button1"
    />


第二个XML
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/button2"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#00ff00"
android:textAllCaps="false"
android:text="Button2"
/>

对第二个活动的注册

  • 写回答

3条回答 默认 最新

  • 午夜学徒xpf 2016-05-31 14:57
    关注

    已解决,
    @Override
    protected void onCreate(Bundle savedInstanceState){
    }

    protected void onCreate(Bundle savedInstanceState){
    }
    的区别.改了之后就行了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于PLUS模型中kapaa值的问题
  • ¥15 关于博途V17进行仿真时无法建立连接问题
  • ¥15 请问下这个红框里面是什么文档或者记事本编辑器
  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号