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日

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格