【问题标题】:Retrieve checked radio button data and send to the another activity when button is pressed检索选中的单选按钮数据并在按下按钮时发送到另一个活动
【发布时间】:2011-08-15 09:07:39
【问题描述】:

我有一个问题:我有两个单选按钮作为 Imagebutton 和一个按钮。

当我单击 Imagebutton 一个时,我想读取该值并将其发送到其他活动,当我按下按钮时我该怎么办?

如果可能,请提供一段代码

【问题讨论】:

    标签: android button radio-button


    【解决方案1】:
    package com.httpconnection;
    
    import java.io.BufferedInputStream;
    import java.io.InputStream;
    import java.net.URL;
    import java.net.URLConnection;
    
    import org.apache.http.util.ByteArrayBuffer;
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.CompoundButton;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    import android.widget.LinearLayout;
    import android.widget.RadioButton;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class httpconnectionActivity extends Activity implements OnCheckedChangeListener {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            LinearLayout layout = new LinearLayout(this);
            layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    
            RadioButton rd1 = new RadioButton(this);
            rd1.setId(1);
            rd1.setOnCheckedChangeListener(this);  
            layout.addView(rd1);
            RadioButton rd2 = new RadioButton(this);
            rd2.setId(2);
            rd2.setOnCheckedChangeListener(this); 
            layout.addView(rd2);
            setContentView(layout);
        }
    
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    
            Intent intent = new Intent(this, xyz.class);
            intent.putExtra("MyKey", buttonView.getId());
            startActivity(intent);
    
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 2020-02-28
      • 2023-04-03
      • 2013-06-22
      相关资源
      最近更新 更多