我不知道怎么上传附件唉!!!1.这是入口,名为WidgetAcitivity,因为当时不小心把Activity打错,打成Acitivity了。
package com.example.chapter4_ui;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.ToggleButton;public class WidgetAcitivity extends Activity{
private Button register,cancel;
private ToggleButton marriged;
private RadioButton male,female;
private EditText username,password;
private Spinner position;//下拉列表
private CheckBox reading,swimming;


public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.widget_test);
username=(EditText)findViewById(R.id.username);
password=(EditText)findViewById(R.id.password);
male=(RadioButton)findViewById(R.id.male);
female=(RadioButton)findViewById(R.id.female);
reading=(CheckBox)findViewById(R.id.reading);
swimming=(CheckBox)findViewById(R.id.swimming);
marriged=(ToggleButton)findViewById(R.id.married);
position=(Spinner)findViewById(R.id.position);
//下拉列表项数组
String[] str={"CEO","CFO","PM"};
//数组下拉列表适配器
ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_spinner_item,str);
position.setAdapter(aa);
register=(Button)findViewById(R.id.register);
cancel=(Button)findViewById(R.id.cancel);

//添加按钮的单击事件监听器
register.setOnClickListener(new OnClickListener(){
public void onClick(View v){
//实例化Bundle对象,保存属性
//Bundle就是存储数据的键值对,可以用在两个Activity中传递数据,可以添加到Intent中
Bundle b=new Bundle();
b.putString("username", "用户名称:"+username.getText().toString());
b.putString("password", "用户密码:"+password.getText().toString());
if(male.isChecked())
b.putString("gender","性别:男");
else
b.putString("gender","性别:女");
String temp="爱好:";
if(reading.isChecked())
temp+="阅读";
if(swimming.isChecked())
temp+=" 游泳";
b.putString("hobby",temp);
if(marriged.isChecked())
b.putString("marriged","婚否:已婚");
else
b.putString("marriged","婚否:未婚");
b.putString("position","职位:"+position.getSelectedItem().toString());

//实例化Intent,跳转到ResultActivity
Intent intent=new Intent(WidgetAcitivity.this,ResultActivity.class);
    //将Bundle添加到intent
intent.putExtra("data",b);
startActivity(intent);
}
});
}}
2.这是需要跳转到的Activity
package com.example.chapter4_ui;import java.util.ArrayList;
import java.util.List;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;public class ResultActivity extends Activity{
private ListView listView;

protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
listView=(ListView)findViewById(R.id.ListView01);
Intent intent =this.getIntent();
Bundle b=intent.getBundleExtra("data");

List list=new ArrayList();
//从Bundle中获得属性,添加到List

list.add(b.getString("username"));
list.add(b.getString("password"));
list.add(b.getString("position"));
list.add(b.getString("gender"));
list.add(b.getString("hobby"));
list.add(b.getString("marriged"));
//实例化数组适配器
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_checked,list);
listView.setAdapter(adapter);
}}3.这是布局,名为widget_test
<?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:orientation="vertical" >
    
    <TableLayout 
        android:id="@+id/TableLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:collapseColumns="3"
        android:stretchColumns="1">
        
        <TableRow 
            android:id="@+id/TableRow01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView
                android:text="用户名称"
                android:id="@+id/TextView01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
            
            <EditText 
                android:text=""
                android:id="@+id/username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
        </TableRow>
        
        <TableRow
            android:id="@+id/TableRow02"
            android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            <TextView
                android:text="用户密码"
                android:id="@+id/TextView02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
            
            <EditText
                android:text=""
                android:id="@+id/password"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:password="true"></EditText>
        </TableRow>
        
        <TableRow 
            android:id="@+id/TableRow03"
            android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            <TextView
                android:text="性别"
                android:id="@+id/TextView03"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
            <RadioGroup
                android:id="@+id/gender_g"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <RadioButton 
                    android:text="男"
                    android:id="@+id/male"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <RadioButton 
                    android:text="女"
                    android:id="@+id/female"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </RadioGroup>
        </TableRow>
        
        <TableRow
            android:id="@+id/TableRow04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView 
                android:text="婚否"
                android:id="@+id/TextView04"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            
            <ToggleButton
                android:text="@+id/ToggleButton01"
                android:id="@+id/married"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></ToggleButton>
            
        </TableRow>
        
        <TableRow 
            android:id="@+id/TableRow05"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView
                android:text="爱好"
                android:id="@+id/hobby"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
            <CheckBox 
                android:text="阅读"
                android:id="@+id/reading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <CheckBox 
                android:text="游泳"
                android:id="@+id/swimming"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </TableRow>
        
        <TableRow 
            android:id="@+id/TableRow06"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView
                android:text="职务"
                android:id="@+id/TextView05"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></TextView>
            <Spinner
                android:id="@+id/position"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></Spinner>
                
        </TableRow>
        
        <TableRow 
            android:id="@+id/TableRow07"
            android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            
            <Button 
                android:text="取消"
                android:id="@+id/cancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <Button
                android:text="注册"
                android:id="@+id/register"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></Button>
        </TableRow>
    </TableLayout></LinearLayout>4.这是跳转后布局,名为result<?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:orientation="vertical" >
    
    <ListView 
        android:id="@+id/ListView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></ListView></LinearLayout>
哪位好心人帮看看吧~我刚学,也没人指导,自学的,看在我寒假还辛辛苦苦敲代码的份上,请大牛帮看看吧~
我QQ476066180
好心人可以留下邮箱,我把整个打包的文件发给你哦~谢谢啦~小女子感激不尽~!androidlayoutradiobuttonimportlistview

解决方案 »

  1.   

    ResultActivity注册没?要在 AndroidManifest.xml加一条如: <activity android:name="com.example.chapter4_ui.ResultActivity" android:label="abc" />PS 要把错识Log传上来,这样大家才可以针对性地帮你找错。
      

  2.   

    是不是你的Manifest文件注册Activity时注册错了,注册时是WidgetActivity,而代码里是WidgetAcitivity
      

  3.   

    有具体的报错信息吗?可以看下LogCat里面的错误信息的,大部分情况下可能看出原因的。
      

  4.   

    等你以后就会有一种条件反射,在写好一个新的activity之后,调试发现报错,就会马上想到有没有去Manifest注册
      

  5.   

    气氛不错,可以先看看log,这样查问题能快点。
      

  6.   

    麻烦楼主把照片和log贴上,谢谢!