当前位置: 代码迷 >> Android >> android 传值的有关问题
  详细解决方案

android 传值的有关问题

热度:26   发布时间:2016-05-01 21:12:46.0
android 传值的问题
我从注册页面转到另一个页面,为什么至没看到,求指导
Java code
public class MainActivity extends Activity {        private Button cancel,register;    private ToggleButton marriged;    private RadioButton male,female;    private EditText username,password;    private Spinner position;    private CheckBox reading,swimming;        @SuppressWarnings("unchecked")    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        username=(EditText) findViewById(R.id.username);        password=(EditText) findViewById(R.id.password);        male=(RadioButton) findViewById(R.id.male);        female=(RadioButton) findViewById(R.id.female);        swimming=(CheckBox) findViewById(R.id.swimming);        reading=(CheckBox) findViewById(R.id.reading);        marriged=(ToggleButton) findViewById(R.id.marriged);        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() {                        @Override            public void onClick(View v) {                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+="";                    temp+="游泳";                }                b.putString("hobby", temp);                if(marriged.isChecked()){                    b.putString("marriged", "婚否:已婚");                }else{                    b.putString("marriged", "婚否:未婚");                }                b.putString("position", "职位:"+position.getSelectedItem().toString());                Intent intent=new Intent(MainActivity.this,ResultActivity.class);                intent.putExtra("data", b);                startActivity(intent);            }        });            }}

Java code
private 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");        System.out.println(b.getString("username"));        List<String> list=new ArrayList<String>();        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<String> Adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked,list);        listView.setAdapter(Adapter);            }}


------解决方案--------------------
打log或者单步,看看有没有进入result这个activity。如果没有,检查你那个onclick进入没有,如果没有,怎看看为啥没有。如果进入result这个activity了,那么看,是不是中途有地方finish了?如果没有看布局是不是不正确。如果布局正确,看数据是不是正确。
  相关解决方案