Android和CheckBox中的线程处理程序问题

时间:2014-03-31 07:11:26

标签: android multithreading android-intent handler

我想问一下android线程处理程序问题。

在此代码中有两个“CheckBox”,当我选择它时,必须更改下一个Activity

但是当我将代码添加到线程处理程序中时,无法更改下一个Activity。

我已添加AndroidMainfeat.xml

我想问一下“CheckBox”是否能带来价值。

bundle.putString( “男孩”,的getText(0)的ToString()修剪());是正确的吗?

感谢。

public class PersonalInformation extends Activity{


    private Button setbutton ;
    private CheckBox boy,girl;

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_personal_information);
            setTitle("PersonalInformation");

            buildViews();  //user define
        } 

     private void buildViews(){ 

          boy = (CheckBox)findViewById(R.id.boy);
          girl = (CheckBox)findViewById(R.id.girl);         
          setbutton = (Button)findViewById(R.id.setbutton);
          setbutton.setOnClickListener(btsetListener);   
        }
            private OnClickListener btsetListener = new OnClickListener() {     

                public void onClick(View v) {

                    final Handler handler = new Handler();
                    final Runnable callback = new Runnable() {

                        @Override
                        public void run() {

                            if (boy.isChecked()&&girl.isChecked())
                                {
                                    Toast.makeText(PersonalInformation.this, "You can't selected most than two!", Toast.LENGTH_LONG).show();
                                }

                            else if (boy.isChecked())
                                {
                                    Intent intent = new Intent();
                                    intent.setClass(PersonalInformation.this, meau.class);
                                    Bundle bundle = new Bundle();
                                    bundle.putString("boy",getText(0).toString().trim());
                                    intent.putExtras(bundle);
                                    startActivity(intent);                                     
                                }
                            else if (girl.isChecked())
                                {
                                    Intent intent = new Intent();
                                    intent.setClass(PersonalInformation.this, meau.class);
                                    Bundle bundle = new Bundle();
                                    bundle.putString("girl",getText(0).toString().trim());
                                    intent.putExtras(bundle);
                                    startActivity(intent);                          
                                }
                            else
                                {
                                    Toast.makeText(PersonalInformation.this, "You must selected one!", Toast.LENGTH_LONG).show();
                                }

                        }
                    };

                }   
            };
        }

0 个答案:

没有答案