cjrdnb 2022-04-05 16:14 采纳率: 50%
浏览 29
已结题

在eclipse中开发Android程序,用模拟器运行程序,但没有出现程序结果

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" >
    tools:context="com.example.dell.demo0401test.Main2Activity"
        
        
    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content">
        

        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账号"
            android:textSize="18sp" />
        
        <EditText 
            android:id="@+id/et1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true" />
    </LinearLayout>


    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content">
        
        
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码"
            android:textSize="18sp" />
        <EditText
            android:id="@+id/et2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true" />
     </LinearLayout>
     
    
     <Button 
            android:id="@+id/btn1"
            android:layout_width="300dp"
            android:layout_height="wrap_content" 
            android:text="登录" />
        
    
</LinearLayout>


java文件

 

package com.activity.android;

import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    EditText
et1, et2;
    Button
btn1;
    
    
    @Override
  
 protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_list_item);
        initView();
        
        
        
btn1.setOnClickListener(new View.OnClickListener(){
            @Override
            
public void onClick(View v){
                Toast.makeText( MainActivity.
this, "登录",Toast.LENGTH_SHORT).show ();
            }
        });
    
    
btn1.setOnClickListener(new View.OnClickListener(){
        @Override
        
public void onClick(View v) {
            String s1 =
et1.getText().toString();
            String s2 =
et2.getText().toString();
            
if (s1.equals("bizideal")&&s2.equals("123456")){
                Toast.makeText( MainActivity.
this, "登录成功",Toast.LENGTH_SHORT).show();
            }
else {
                Toast.makeText( MainActivity.
this, "登录失败",Toast.LENGTH_SHORT).show();
            }
        }
    });
}
    
    
  
 private void initView() {
        
et1 = (EditText) findViewById(R.id.edit);
        
et2 = (EditText) findViewById(R.id.edit);
        
btn1 = (Button) findViewById(R.id.button1);
    }
}

 

  • 写回答

2条回答 默认 最新

  • 不会写代码的猴子 Android领域优质创作者 2022-04-06 09:41
    关注

    img


    你的layout文件夹下有这个布局文件吗

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

报告相同问题?

问题事件

  • 系统已结题 5月20日
  • 已采纳回答 5月12日
  • 创建了问题 4月5日

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容