我在 android 中做了一个简单的应用程序,有两个活动,在第一个活动中,它是一个包含一些编辑文本和单选组和一个复选框的表单。但是单选按钮有问题。它的值不会转到另一个活动。我试过了以下:
act1.java
package com.example.myweb;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends Activity {
public String EXTRA_MESSAGE = "com.example.myweb";
Button b;
EditText ed1,ed2,ed3,ed4;
RadioGroup rg;
RadioButton rb;
CheckBox c1;
// boolean yes = c1.isChecked();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rg=(RadioGroup)findViewById(R.id.radioGroup1);
b =(Button)findViewById(R.id.send);
ed1=(EditText)findViewById(R.id.edit_msg);
ed2=(EditText)findViewById(R.id.edit_msg1);
ed3=(EditText)findViewById(R.id.edit_msg3);
ed4=(EditText)findViewById(R.id.edit_msg4);
// r1=(RadioButton)findViewById(R.id.radioButton1);
// r2=(RadioButton)findViewById(R.id.radioButton2);
c1=(CheckBox)findViewById(R.id.ck1);
int id=rg.getCheckedRadioButtonId();
rb=(RadioButton)findViewById(id);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Intent i = new Intent(MainActivity.this,Act2.class);
Bundle b=new Bundle();
final String fname=ed1.getText().toString();
final String lname=ed2.getText().toString();
final String fon=ed3.getText().toString();
final String city= ed4.getText().toString();
final String gen = rb.getText().toString();
if(c1.isChecked()){
Intent i = new Intent(MainActivity.this,Act2.class);
i.putExtra("Extra__fname", fname);
i.putExtra("Extra__lname", lname);
i.putExtra("Extra__fon", fon);
i.putExtra("Extra__city", city);
i.putExtra("gen", gen);
startActivity(i);
}
else{
Toast.makeText(getApplicationContext(), "Please accept it", 1).show();
}
}
});
}
}
act2.java
package com.example.myweb;
import org.w3c.dom.Text;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Act2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act2);
TextView t = (TextView)findViewById(R.id.tv1);
TextView t1 = (TextView)findViewById(R.id.tv2);
TextView t2 = (TextView)findViewById(R.id.tv3);
TextView t3 = (TextView)findViewById(R.id.tv4);
TextView t4 = (TextView)findViewById(R.id.tv5);
Bundle bundle = getIntent().getExtras();
String fname= bundle.getString("Extra__fname");
String lname= bundle.getString("Extra__lname");
String fon= bundle.getString("Extra__fon");
String city= bundle.getString("Extra__city");
String gen= bundle.getString("gen");
t.setText(fname);
t1.setText(lname);
t2.setText(fon);
t3.setText(city);
t4.setText(gen);
}
}
日志猫
05-02 09:55:28.492: E/ActivityThread(554): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cf6fe0 that was originally bound here
05-02 09:55:28.492: E/ActivityThread(554): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cf6fe0 that was originally bound here
05-02 09:55:28.492: E/ActivityThread(554): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
05-02 09:55:28.492: E/ActivityThread(554): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
05-02 09:55:28.492: E/ActivityThread(554): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
05-02 09:55:28.492: E/ActivityThread(554): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
05-02 09:55:28.492: E/ActivityThread(554): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
05-02 09:55:28.492: E/ActivityThread(554): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
05-02 09:55:28.492: E/ActivityThread(554): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-02 09:55:28.492: E/ActivityThread(554): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-02 09:55:28.492: E/ActivityThread(554): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-02 09:55:28.492: E/ActivityThread(554): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-02 09:55:28.492: E/ActivityThread(554): at java.lang.Thread.run(Thread.java:856)
05-02 09:55:28.592: E/StrictMode(554): null
05-02 09:55:28.592: E/StrictMode(554): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cf6fe0 that was originally bound here
05-02 09:55:28.592: E/StrictMode(554): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
05-02 09:55:28.592: E/StrictMode(554): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
05-02 09:55:28.592: E/StrictMode(554): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
05-02 09:55:28.592: E/StrictMode(554): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
05-02 09:55:28.592: E/StrictMode(554): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
05-02 09:55:28.592: E/StrictMode(554): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
05-02 09:55:28.592: E/StrictMode(554): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
05-02 09:55:28.592: E/StrictMode(554): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
05-02 09:55:28.592: E/StrictMode(554): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
05-02 09:55:28.592: E/StrictMode(554): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
05-02 09:55:28.592: E/StrictMode(554): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
05-02 09:55:28.592: E/StrictMode(554): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
05-02 09:55:28.592: E/StrictMode(554): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-02 09:55:28.592: E/StrictMode(554): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-02 09:55:28.592: E/StrictMode(554): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-02 09:55:28.592: E/StrictMode(554): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-02 09:55:28.592: E/StrictMode(554): at java.lang.Thread.run(Thread.java:856)
05-02 09:55:28.592: W/ActivityManager(274): Unbind failed: could not find connection for android.os.BinderProxy@410f7970