为什么写的安卓程序一涉及到在一个Activity中输入一段内容传递到另外一个活动的上显示的时候就停止运行?
大神们!我是个初学者,求解求帮助呀~我用的是eclipse写的一下是代码:MainActivity:packagecom.Founder.demo3;importandr...
大神们!我是个初学者,求解求帮助呀~我用的是eclipse写的
一下是代码:
MainActivity:
package com.Founder.demo3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText edit1= (EditText)findViewById(R.id.edit1);
private Button button1 = (Button)findViewById(R.id.button1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
String edit_get = edit1.getText().toString();
intent.setClass(MainActivity.this, OtherActivity.class);
intent.putExtra("input", edit_get);
MainActivity.this.startActivity(intent);
}
}
}
OtherActivity:
package com.Founder.demo3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class OtherActivity extends Activity {
private TextView text1 = (TextView)findViewById(R.id.text1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent = getIntent();
String output = intent.getExtras().toString();
text1.setText(output);
}
}
字数限制...我把剩下的l就上图了~ 展开
一下是代码:
MainActivity:
package com.Founder.demo3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText edit1= (EditText)findViewById(R.id.edit1);
private Button button1 = (Button)findViewById(R.id.button1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
String edit_get = edit1.getText().toString();
intent.setClass(MainActivity.this, OtherActivity.class);
intent.putExtra("input", edit_get);
MainActivity.this.startActivity(intent);
}
}
}
OtherActivity:
package com.Founder.demo3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class OtherActivity extends Activity {
private TextView text1 = (TextView)findViewById(R.id.text1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent = getIntent();
String output = intent.getExtras().toString();
text1.setText(output);
}
}
字数限制...我把剩下的l就上图了~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询