嗨,我最近问了一个关于我的应用程序的问题,这里的好人发现它会强制关闭,因为我的图像没有被位图工厂正确处理,但是作为一个业余爱好者,我决定取出图像以确保我的代码是好的....它不是
我想要的主要是打开第二个活动,其中列出了 4 个按钮,最上面的一个也带你洗澡活动
我所拥有的是主要跳过第二个活动并带你太洗澡如果你按下它会带你太第二个活动但这里的按钮什么也不做
但是我的代码没有错误,并且应用程序从不强制关闭,所以我也只是发布代码或 logcat 吗?
任何帮助表示赞赏
main.java
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class main extends Activity {
Button ok;
EditText name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.editText);
ok=(Button)findViewById(R.id.button);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String nameStr = name.getText().toString();
Intent intent = new Intent(getApplicationContext(), secondactivity.class);
intent.putExtra("NAMEDATA",nameStr);
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.main, menu);
return true;
}
}
secondactivity.java
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
public class secondactivity extends Activity {
TextView t;
Button button;
Button button2;
Button button3;
Button button4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
t = (TextView)findViewById(R.id.textView3);
String n = this.getIntent().getStringExtra("NAMEDATA");
t.setText(n);
button = (Button)findViewById(R.id.button);
button2 = (Button)findViewById(R.id.button2);
button3 = (Button)findViewById(R.id.button3);
button4 = (Button)findViewById(R.id.button4);
setButtonOnClickListener();
}
private void setButtonOnClickListener(){
Intent intent = new Intent(secondactivity.this, bathactivity.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.second, menu);
return true;
}
}
沐浴活动.java
package com.example.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Button;
public class bathactivity extends Activity {
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bath);
button = (Button)findViewById(R.id.nextbutton);
}
}