Таким образом, у меня есть инфлятор меню, и когда я выбираю что-то в нем, моя программа закрывается, и я верю, что это потому, что класс также реализует onclicklistener для массива кнопок, которые я должен добавить. Вот некоторые из соответствующих кодов:
package com.riley.howmany;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
public class howMany extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//I have to use a dynamic layout because it changes based on user options.
//As of right now it is just in a for loop because the settings menu won't open
//because of this issue. I hope this makes sense.
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);
ll.setPadding(1,1,1,1);
TextView tv = new TextView(this);
tv.setText("Dynamic layouts ftw!");
ll.addView(tv);
//Each button press actually performs the same code for that individual button
for (int c=0; c<=10; c++) {
Button b = new Button (this);
b.setText("Button:"+" "+"0");
b.setTextSize(10.0f);
b.setOnClickListener(this);
ll.addView(b);
}
this.setContentView(sv);
}
public void onClick(View view) {
//handle each button click
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menus, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent(this, Setting.class);
startActivity(intent);
return true;
}
}
Большое спасибо за любые советы, которые вы можете дать!
EDIT / UPDATE! * * 1006
Хорошо, я нашел исправление. Вот оно:
@Override
public boolean onCreateOptionsMenu (Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menus, menu);
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item) {
startActivity(new Intent(this, Setting.class));
return true;
}
Теперь это прекрасно работает! Спасибо за помощь.