WiMemory 2017-04-08 09:44 采纳率: 0%
浏览 2502

Activity跳转失败,点击跳转按钮后黑屏卡住

Activity跳转失败,点击跳转按钮后黑屏卡住,估计是otheractivity启动失败,android 小白

activity_other.xml

 <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:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="35dp"
        android:text="@string/activity_other_headtext"
        android:gravity="center"
        android:background="#E0E0E0" />
    <TextView android:layout_width="fill_parent"
        android:layout_height="35dp"
        android:text="@string/activity_other_meg"
        android:gravity="center"/>

    <TableLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="160dp"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:padding="5dp"
                android:text="@string/activity_other_username" />
            <TextView
                android:id="@+id/activity_other_username"
                android:layout_width="160dp"
                android:layout_height="wrap_content"
                android:padding="5dp"/>
        </TableRow>

        <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text="@string/activity_other_sex"
            android:padding="5dp"/>
            <TextView
                android:layout_width="160dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:id="@+id/activity_other_sex"
                android:text="@string/activity_other_null"/>
        </TableRow>

        <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
             <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text="@string/activity_other_phonenum"
            android:padding="5dp"/>
            <TextView
                android:layout_width="160dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:id="@+id/activity_other_phonenum"
                android:text="@string/activity_other_null"/>
        </TableRow>

        <TableRow 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
             <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text="@string/activity_other_QQ"
            android:padding="5dp"/>
            <TextView
                android:layout_width="160dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:id="@+id/activity_other_QQ"
                android:text="@string/activity_other_null"/>
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/activity_other_Button"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/activity_other_know_button">
    </Button>
</LinearLayout>

Mainactivity.java

 package com.example.p105092015050;

import java.security.PublicKey;

import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.inputmethodservice.Keyboard.Key;
import android.os.Bundle;
import android.os.storage.OnObbStateChangeListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    private EditText username_EText=null;
    private EditText phonenum_EText=null;
    private EditText QQ_EText=null;
    private EditText passwd_EText=null;
    private EditText passwd_EText_reptition=null;
    private CheckBox checkBox=null;
    private Button regist_button=null;
    private RadioGroup sex_radiogroup=null;

    public char sex;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    public void init() {
        username_EText=(EditText)findViewById(R.id.activity_main_EText_username);
        sex_radiogroup=(RadioGroup)findViewById(R.id.radiogroup);
        phonenum_EText=(EditText)findViewById(R.id.activity_main_EText_phonenum);
        QQ_EText=(EditText)findViewById(R.id.activity_main_EText_QQ);
        passwd_EText=(EditText)findViewById(R.id.activity_main_EText_password);
        passwd_EText_reptition=(EditText)findViewById(R.id.activity_main_EText_password_reptition);
        checkBox=(CheckBox)findViewById(R.id.activity_main_CheckBox);
        regist_button=(Button)findViewById(R.id.activity_main_Button_register);

        checkBox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if(checkBox.isChecked())
                    regist_button.setEnabled(true);
                else regist_button.setEnabled(false);
            }
        });
        sex_radiogroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId==R.id.activity_main_RadioButton_man)
                    sex='男';
                else if(checkedId==R.id.activity_main_RadioButton_woman)
                    sex='女';
            }
        });
        regist_button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if(username_EText.getText().toString().length() == 0){
                    Toast.makeText(MainActivity.this,"用户名不能为空", Toast.LENGTH_SHORT).show();
                }
                else if(passwd_EText.getText().toString().length() == 0 ||passwd_EText_reptition.getText().toString().length() == 0){
                    Toast.makeText(MainActivity.this,"密码不能为空", Toast.LENGTH_SHORT).show();
                }
                else if(!passwd_EText.getText().toString().equals(passwd_EText_reptition.getText().toString())){
                    Toast.makeText(MainActivity.this,"密码不一致", Toast.LENGTH_SHORT).show();
                }
                else {
                    Intent intent=new Intent(MainActivity.this,OtherActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("username",username_EText.getText().toString());
                    bundle.putChar("sex", sex);
                    bundle.putString("phonenum",phonenum_EText.getText().toString());
                    bundle.putString("QQ",QQ_EText.getText().toString());

                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

OtherActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class OtherActivity extends Activity {

    private Button button=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);

        button=(Button)findViewById(R.id.activity_other_Button);
        Bundle bundle=this.getIntent().getExtras();

        TextView username=(TextView)findViewById(R.id.activity_other_username);
        username.setText(bundle.getString("username"));

        while(bundle.getString("sex") != null){
            TextView phonenum=(TextView)findViewById(R.id.activity_other_sex);
            phonenum.setText(bundle.getString("sex"));
        }
        while(bundle.getString("phonenum") != null){
            TextView phonenum=(TextView)findViewById(R.id.activity_other_phonenum);
            phonenum.setText(bundle.getString("phonenum"));
        }
        while(bundle.getString("QQ") != null){
            TextView phonenum=(TextView)findViewById(R.id.activity_other_QQ);
            phonenum.setText(bundle.getString("QQ"));
        }

        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(OtherActivity.this, "注册成功,等待进入主界面", Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.other, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
  • 写回答

2条回答

  • dabocaiqq 2017-04-08 15:26
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用