所以,我刚刚开始查看并在活动之间移动。我以为我得到了我想要的东西。我修复了所有错误,但现在当我测试应用程序时它崩溃了。我是android和eclipse的新手。所以我不确定发生了什么。这是我的 MainActivity.java:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String info = intent.getStringExtra("info_key");
TextView text = (TextView) findViewById(R.id.nametext);
text.setText(info);
}
//opens a new activity.
public void openAddItem (View v){
Intent intent = new Intent (this, Additem.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
这是我的第二个活动;Additem.java:
package com.grocerylist;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Additem extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_additem);
}
public void additem (View v){
EditText text = (EditText)findViewById(R.id.itemname);
String info = text.getText().toString();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("info_key", info);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_additem, menu);
return true;
}
}
谢谢,我很肯定问题出在我放置身份证的地方。