向复选框添加意图

时间:2015-10-12 08:19:13

标签: java android android-intent android-activity

我的活动A中有复选框。

我想知道的是,如果用户检查给定的一个框,那么我想将其链接到另一个活动,以便当用户选中该框时他会转到该活动B,同样所有其他框都是与不同的活动有关。

我尝试了按钮中的意图代码,但这似乎不起作用。 如果我能获得特定代码和导入,那么提前感谢会非常有用。

public void onClick(View view){
Intent i = new Intent(this, 2nd java.class);
startActivity(i);
}

我使用上面的按钮。

2 个答案:

答案 0 :(得分:1)

您需要在下面的侦听器中添加您的代码:

 yourCheckboxView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (isChecked){
                   Intent i = new Intent(this, 2nd java.class);
                   startActivity(i);
            }
        }

    });

谢谢.. !!

答案 1 :(得分:0)

private void getUDPData() throws IOException {

        class ProcessUPDTask extends AsyncTask<String, Void, Socket> {

            private Exception exception;

            private Socket socket;

            public ProcessUPDTask() throws IOException {

            }

            private void runThread(){
                new Thread() {
                    public void run() {
                        Toast.makeText(activity, "Own Message",       Toast.LENGTH_LONG).show();
                           }
                }.start();
             }


            protected Socket doInBackground(String... urls) {

                try {
                    try{
                        socket = new Socket(some_ip, some_port); 
                        socket.setSoTimeout(1500);
                    }
                    catch(IOException e) {
                       e.printStackTrace();
                    }

                    Log.d("TAG","this line is reached");
                    while(true){
                        try {
                            dataInputStream = new DataInputStream(socket.getInputStream());
                            dataOutputStream = new DataOutputStream(socket.getOutputStream());
                            System.out.println("ip: " + socket.getInetAddress());
                            System.out.println("message: " + dataInputStream.readUTF());
                            dataOutputStream.writeUTF("Hello!");
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        finally{
                            if( socket!= null){
                                try {
                                    socket.close();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }

                            if( dataInputStream!= null){
                                try {
                                    dataInputStream.close();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }

                            if( dataOutputStream!= null){
                                try {
                                    dataOutputStream.close();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    this.exception = e;
                    e.printStackTrace();
                    return null;
                }
            }
            protected void onPostExecute(Socket socket) {
                // TODO: check this.exception
                // TODO: do something with the feed
            }
        }
        new ProcessUPDTask().execute();
    }