本帖最后由 zengting 于 2012-02-06 12:11:44 编辑

解决方案 »

  1.   

    可以查找帮助,用intent相关的控件.
      

  2.   

    我的问题是对话框传参数,不是Activity传参数
      

  3.   

    你在Eclipse中Project==》Build Project 把项目编译下R.java中就会有Button的id了
      

  4.   

    现在有id了,但我用
    public void onClick(DialogInterface dialog,
    int whichButton)
    {
    TextView edit=(TextView)findViewById(R.id.username_edit);
    Log.d("log", edit.getText().toString());
    }里面点击后出错,是怎么回事呢?
     TextView edit=(TextView)findViewById(R.id.username_edit);
    获取不了R.id.username_edit数据吗?
      

  5.   

    这里的View是dialog的View,所以要用loginLayout.findfindViewById();
      

  6.   

    首先你的布局写得不仅不规范,而且id也没有加上,所以你找不到id。两外,要获取布局中的控件,需要像5楼所说那样,因为这个布局是对话框的布局,应该用loginLayout.findViewById(R.id.accountName)。你所用的方法只有在调用了setContentView(R.layout.login),让这个布局属于Activity,才能直接调用FindViewById找到相应的控件。
    修正的布局文件如下,希望对你有用<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp">
    <TextView 
    android:layout_width="wrap_content" 
    android:hint="用户名:"
    android:textSize="20dp" 
    android:layout_height="wrap_content" />
    <EditText
    android:id="@+id/accountName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
    </LinearLayout>
    <LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp">
    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:hint="密 码:"
    android:textSize="20dp" />
    <EditText 
    android:id="@+id/passwd"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:password="true" />
    </LinearLayout>
      

  7.   

    获取用户名和密码的方法:调用控件的getText()方法即返回该空间的内容。
      

  8.   

    后面加上.Tostring()是获得的内容为字符串形式