У меня есть приложение, содержащее две кнопки, обе из которых предполагают, что пользователь должен перейти на ту же страницу. Вот для них файл.java:
public class PageTwoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2);
Button home = (Button) findViewById(R.id.ButtonHome);
home.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), GuideApplicationActivity.class);
startActivityForResult(myIntent, 0);
Button home2 = (Button) findViewById(R.id.ButtonHome2);
home2.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent2 = new Intent(view.getContext(), GuideApplicationActivity.class);
startActivityForResult(myIntent2, 0);
}
});}
});};};
Любая помощь? Если вам нужно посмотреть другие файлы, пожалуйста, спросите. Заранее спасибо,
Что-то не так с вашими открывающими и закрывающимися тегами. Попробуй это:
public class MainMenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2);
Button home = (Button) findViewById(R.id.ButtonHome);
home.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), GuideApplicationActivity.class);
startActivityForResult(myIntent, 0);
}
});
Button home2 = (Button) findViewById(R.id.ButtonHome2);
home2.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent myIntent2 = new Intent(view.getContext(), GuideApplicationActivity.class);
startActivityForResult(myIntent2, 0);
}
});
}
}
Попробуйте использовать этот код внутри вашего метода onClick(...)
.
Intent myIntent2 = new Intent(PageTwoActivity.this, GuideApplicationActivity.class);
PageTwoActivity.this.startActivityForResult(myIntent2, 0);
Я думаю, что у вас что-то не так в коде. попробуй это:
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class PageTwoActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page2);
Button home = (Button) findViewById(R.id.ButtonHome);
home.setOnClickListener(this);
Button home2 = (Button) findViewById(R.id.ButtonHome2);
home2.setOnClickListener(this);
}
@Override
public void onClick(View v){
Intent myIntent = new Intent(this, GuideApplicationActivity.class);
startActivityForResult(myIntent, 0);
}
}
NB: ваше GuideApplicationActivity
должно быть объявлено в вашем файле манифеста