2013.4.11

来源:互联网 发布:wannacry蠕虫勒索软件 编辑:程序博客网 时间:2024/06/15 14:12
   已经自学了几天的android编程,今天决定开始记录下来。
   这几天可谓是艰难重重啊。一开始,按着书上写的安装JDK,SDK,eclipse时就遇到麻烦。不知道问什么,我想把JDK放G盘,可是发现安装eclipse后显示错误。弄了很久都没解决,后来心一横,直接全部按原路径安装,不做更改,才成功运行。
   之后,就开始调试AVD,额...AVD的硬伤就是开机速度奇慢,开始我以为是出问题了,后来去网上一查,才发现原来这是个普遍的现象。不过值得庆幸的是,每次修改程序代码后不用关闭AVD,可以直接退出程序再运行。然后因为嫌慢,我就打算用真机调试。手头有一部Sony的ST25i,于是接上电脑用。装完了驱动(其实早就装了),打开eclipse,打算进入,可是显示出错,具体如下:
  

   [2013-04-07 22:09:17 - TProgram] Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
   [2013-04-07 22:09:17 - TProgram] Please check logcat output for more details.
   [2013-04-07 22:09:17 - TProgram] Launch canceled!

   上网查了一下,发现不知所云,不过倒是感觉到了应该是Project建立的版本跟手机中android版本不合的问题。于是马上重建了一个Project,运行,果然成功...心中顿时畅顺....
   现在的新问题倒是出来了,不知道我对书上的理解对不对,我把如下代码输入后:


   
<?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="fill_parent"
    android:orientation="vertical" >
    
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="性别:" />


    <EditText
        android:id="@+id/edtSex"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="text" />


   
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="年龄:" />


    <EditText
        android:id="@+id/edtAge"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number" />
    
    <Button
        android:id="@+id/btnDoSug"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="婚姻建议" />
    
    <TextView
        android:id="@+id/txtResult"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="结果:" />
    
    package tw.android;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.*;
    
    public class MarriSug extends Activity {
       
       private Button btnDoSug;
       private EditText edtSex,edtAge;
       private TextView txtResult;
       
       @Override
       public void onCreate(Bundle savedInstanceState){
         super.onCreate(saveInstanceState);
         setContentView(R.layout,main);
         
         btnDoSug = (Button)findViewById(R.id.btnDoSug);
         edtSex = (EditText)findViewById(R.id.edtSex);
         txtResult = (TextView)findViewById(R.id.txtResult);
         
         btnDoSug.setOnClickListener(btnDoSugOnClick);
     }
     
     private Button.OnClickListener btnDoSugOnClick = new Button.OnClickListener(){
       public void onClick(View v){
       
         String strSex = edtSex.getText().toString();
         int iAge = Integer.parseInt(edtAge.getText().toString());
         
         String strSug ="结果;";
         if(strSex.equals("男"))
           if(iAge>33)
              strSug += "赶快结婚";
           else if(iAge>28)
              strSug += "开始找对象";
           else
              strSug += "不急";
         else
           if(iAge>30) 
              strSug += "赶快结婚";
           else if(iAge>25)
              strSug += "开始找对象";
           else
              strSug += "不急";  
              
          txtResult.setText(strSug);
         }
       };  
     }            
                      
</LinearLayout> 
                      
 


发现各个模块的显示是没有问题,可是按了按键后没有反应,没有弹出预期的窗口,估计是我哪个重要的步骤弄错了....
原创粉丝点击