How to transfer and save numbers - java

This code right here is a random math questionnaire and I want to know how to be able to transfer the amount of questions answered right and wrong to a separate stats page after each time they answer a question. I want the stats page to save the numbers so that if the user exits the program and then goes back on later they can still look at their total right answered questions and wrong answered questions. Ive been looking all over the internet and cant find a good way to learn this. If anyone has some advice I would really appreciate it. btw this is pretty much all the code in the main page; I didn't add the stats page code (because it has pretty much nothing.)
Pushme1-4 are the buttons and the AdditionEasyRight and AdditionEasyWrong are the number counts that are displayed on the main page.
public class AdditionEasy extends AppCompatActivity {
int countCNumAddE = 0;
int countWNumAddE = 0;
boolean hasAnswered;
public static final String MY_PREFS_NAME = "MyPrefsFile";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addition);
final TextView count = (TextView) findViewById(R.id.Count);
final TextView count2 = (TextView) findViewById(R.id.Count2);
Button homeButton = (Button) findViewById(R.id.homeButton);
super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
final TextView textOne = (TextView) findViewById(R.id.textView);
final TextView textTwo = (TextView) findViewById(R.id.textView2);
final Button pushMe1 = (Button) findViewById(R.id.button1);
final Button pushMe2 = (Button) findViewById(R.id.button2);
final Button pushMe3 = (Button) findViewById(R.id.button3);
final Button pushMe4 = (Button) findViewById(R.id.button4);
final Button begin = (Button) findViewById(R.id.begin);
begin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
hasAnswered = false;
pushMe1.setEnabled(true);
pushMe2.setEnabled(true);
pushMe3.setEnabled(true);
pushMe4.setEnabled(true);
begin.setVisibility(View.INVISIBLE);
pushMe1.setVisibility(View.VISIBLE);
pushMe2.setVisibility(View.VISIBLE);
pushMe3.setVisibility(View.VISIBLE);
pushMe4.setVisibility(View.VISIBLE);
pushMe1.setTextColor(Color.BLACK);
pushMe2.setTextColor(Color.BLACK);
pushMe3.setTextColor(Color.BLACK);
pushMe4.setTextColor(Color.BLACK);
pushMe1.setTextSize(20);
pushMe2.setTextSize(20);
pushMe3.setTextSize(20);
pushMe4.setTextSize(20);
textTwo.setText("");
String randGenChoice1 = "";
String randGenChoice2 = "";
String randGenChoice3 = "";
String randGenChoice4 = "";
String randText2 = "";
String randText3 = "";
Random RandomNum = new Random();
int randChoice1 = RandomNum.nextInt(40) + 1;
int randChoice2 = RandomNum.nextInt(40) + 1;
int randChoice3 = RandomNum.nextInt(40) + 1;
int randChoice4 = RandomNum.nextInt(40) + 1;
int rando2 = RandomNum.nextInt(20) + 1;
int rando3 = RandomNum.nextInt(20) + 1;
int pick = RandomNum.nextInt(4);
randGenChoice1 = Integer.toString(randChoice1);
randGenChoice2 = Integer.toString(randChoice2);
randGenChoice3 = Integer.toString(randChoice3);
randGenChoice4 = Integer.toString(randChoice4);
randText2 = Integer.toString(rando2);
randText3 = Integer.toString(rando3);
int value1;
int value2;
value1 = Integer.parseInt(randText2);
value2 = Integer.parseInt(randText3);
final int value = value1 + value2;
String line = randText2 + " + " + randText3;
textOne.setText(line);
final String answer;
answer = Integer.toString(value);
pushMe1.setText(randGenChoice1);
pushMe2.setText(randGenChoice2);
pushMe3.setText(randGenChoice3);
pushMe4.setText(randGenChoice4);
Button[] choice = {pushMe1, pushMe2, pushMe3, pushMe4};
Button display = choice[pick];
display.setText(answer);
pushMe1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int buttonAnswer = Integer.parseInt(pushMe1.getText().toString());
if (buttonAnswer == value) {
begin.setVisibility(View.VISIBLE);
textTwo.setText("Correct!");
textTwo.setTextColor(Color.BLACK);
pushMe1.setTextColor(Color.GREEN);
pushMe1.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyRight = Integer.toString(++countCNumAddE);
count.setText(AdditionEasyRight);
hasAnswered = true;
}
begin.setText("New Question");
begin.setTextSize(20);
pushMe2.setVisibility(View.INVISIBLE);
pushMe3.setVisibility(View.INVISIBLE);
pushMe4.setVisibility(View.INVISIBLE);
pushMe1.setEnabled(false);
pushMe2.setEnabled(false);
pushMe3.setEnabled(false);
pushMe4.setEnabled(false);
}else{
textTwo.setText("Wrong!");
textTwo.setTextColor(Color.BLACK);
pushMe1.setTextColor(Color.RED);
pushMe1.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyWrong = Integer.toString(++countWNumAddE);
count2.setText(AdditionEasyWrong);
hasAnswered = true;
}
pushMe1.setEnabled(false);
}
}
});
pushMe2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int buttonAnswer = Integer.parseInt(pushMe2.getText().toString());
if (buttonAnswer == value) {
begin.setVisibility(View.VISIBLE);
textTwo.setText("Correct!");
textTwo.setTextColor(Color.BLACK);
pushMe2.setTextColor(Color.GREEN);
pushMe2.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyRight = Integer.toString(++countCNumAddE);
count.setText(AdditionEasyRight);
hasAnswered = true;
}
begin.setText("New Question");
begin.setTextSize(20);
pushMe1.setVisibility(View.INVISIBLE);
pushMe3.setVisibility(View.INVISIBLE);
pushMe4.setVisibility(View.INVISIBLE);
pushMe1.setEnabled(false);
pushMe2.setEnabled(false);
pushMe3.setEnabled(false);
pushMe4.setEnabled(false);
}else{
textTwo.setText("Wrong!");
textTwo.setTextColor(Color.BLACK);
pushMe2.setTextColor(Color.RED);
pushMe2.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyWrong = Integer.toString(++countWNumAddE);
count2.setText(AdditionEasyWrong);
hasAnswered = true;
}
pushMe2.setEnabled(false);
}
}
});
pushMe3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int buttonAnswer = Integer.parseInt(pushMe3.getText().toString());
if (buttonAnswer == value) {
begin.setVisibility(View.VISIBLE);
textTwo.setText("Correct!");
textTwo.setTextColor(Color.BLACK);
pushMe3.setTextColor(Color.GREEN);
pushMe3.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyRight = Integer.toString(++countCNumAddE);
count.setText(AdditionEasyRight);
hasAnswered = true;
}
begin.setText("New Question");
begin.setTextSize(20);
pushMe1.setVisibility(View.INVISIBLE);
pushMe2.setVisibility(View.INVISIBLE);
pushMe4.setVisibility(View.INVISIBLE);
pushMe1.setEnabled(false);
pushMe2.setEnabled(false);
pushMe3.setEnabled(false);
pushMe4.setEnabled(false);
}else{
textTwo.setText("Wrong!");
textTwo.setTextColor(Color.BLACK);
pushMe3.setTextColor(Color.RED);
pushMe3.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyWrong = Integer.toString(++countWNumAddE);
count2.setText(AdditionEasyWrong);
hasAnswered = true;
}
pushMe3.setEnabled(false);
}
}
});
pushMe4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int buttonAnswer = Integer.parseInt(pushMe4.getText().toString());
if (buttonAnswer == value) {
begin.setVisibility(View.VISIBLE);
textTwo.setText("Correct!");
textTwo.setTextColor(Color.BLACK);
pushMe4.setTextColor(Color.GREEN);
pushMe4.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyRight = Integer.toString(++countCNumAddE);
count.setText(AdditionEasyRight);
hasAnswered = true;
}
begin.setText("New Question");
begin.setTextSize(20);
pushMe1.setVisibility(View.INVISIBLE);
pushMe2.setVisibility(View.INVISIBLE);
pushMe3.setVisibility(View.INVISIBLE);
pushMe1.setEnabled(false);
pushMe2.setEnabled(false);
pushMe3.setEnabled(false);
pushMe4.setEnabled(false);
}else{
textTwo.setText("Wrong!");
textTwo.setTextColor(Color.BLACK);
pushMe4.setTextColor(Color.RED);
pushMe4.setTextSize(30);
if (hasAnswered != true) {
String AdditionEasyWrong = Integer.toString(++countWNumAddE);
count2.setText(AdditionEasyWrong);
hasAnswered = true;
}
pushMe4.setEnabled(false);
}
}
});
}
});
homeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent homepage = new Intent(AdditionEasy.this , Menu.class);
startActivity(homepage);
}
});
}
}

Related

Android Development. RadioButton keeps unselecting

I am building a little quiz app and let's say on Question 1, I select option B, then submit and the quiz gives me the next question. However for question 2 if I try to select B, the RadioButton quickly unchecks itself and it is completely uncheckable, until I select another radio button and then try B again. The pattern is, whatever option I selected in the previous question, is uncheckable in the next question unless I click on a different radiobutton and then try again. I'm attaching my code. Any help please?
public class MainActivity extends AppCompatActivity {
QuestionBank allQuestions = new QuestionBank();
String pickedAnswer = "", correctAnswer = "";
final int numberOfQuestions = allQuestions.list.size();
int questionNumber = 0;
boolean noSelection = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nextQuestion();
}
private void nextQuestion() {
if (questionNumber <= numberOfQuestions - 1) {
TextView questionLabel = (TextView) findViewById(R.id.question_text_view);
String fullQuestion = allQuestions.list.get(questionNumber).questionSet.get("question").toString();
fullQuestion += "\n\na) " + allQuestions.list.get(questionNumber).questionSet.get("a");
fullQuestion += "\nb) " + allQuestions.list.get(questionNumber).questionSet.get("b");
fullQuestion += "\nc) " + allQuestions.list.get(questionNumber).questionSet.get("c");
fullQuestion += "\nd) " + allQuestions.list.get(questionNumber).questionSet.get("d");
correctAnswer = allQuestions.list.get(questionNumber).questionSet.get("answer").toString();
questionLabel.setText(fullQuestion);
questionNumber++;
} else {
restart();
}
}
public void getSelectedAnswer() {
RadioButton radio_1 = (RadioButton) findViewById(R.id.option1_button);
RadioButton radio_2 = (RadioButton) findViewById(R.id.option2_button);
RadioButton radio_3 = (RadioButton) findViewById(R.id.option3_button);
RadioButton radio_4 = (RadioButton) findViewById(R.id.option4_button);
if (radio_1.isChecked()) {
pickedAnswer = "a";
radio_1.setChecked(false);
} else if (radio_2.isChecked()) {
pickedAnswer = "b";
radio_2.setChecked(false);
} else if (radio_3.isChecked()) {
pickedAnswer = "c";
radio_3.setChecked(false);
} else if (radio_4.isChecked()) {
pickedAnswer = "d";
radio_4.setChecked(false);
} else {
noSelection = true;
}
}
public void submitAnswer(View view) {
getSelectedAnswer();
if (noSelection) {
AlertDialog.Builder a_builder = new AlertDialog.Builder(this);
a_builder.setMessage("Please select an answer!");
a_builder.show();
noSelection = false;
} else {
checkAnswer();
nextQuestion();
}
}
public void checkAnswer() {
if (correctAnswer == pickedAnswer) {
AlertDialog.Builder a_builder = new AlertDialog.Builder(this);
a_builder.setMessage("Right Answer!");
a_builder.show();
} else {
AlertDialog.Builder a_builder = new AlertDialog.Builder(this);
a_builder.setMessage("Wrong Answer!");
a_builder.show();
}
pickedAnswer = "";
correctAnswer = "";
}
public void restart() {
questionNumber = 0;
//Collections.shuffle(allQuestions.list);
nextQuestion();
}
}
call setChecked(false) on all the buttons after submitting or before showing next question

Disabling onClick until int = something

public class MainActivity extends AppCompatActivity {
int foulCounterA = 0;
int scoreOnePointTeamA = 0;
int periodCount = 0;
private TextView tv1;
private TextView period;
private Button startbtn, cancelbtn;
private ToggleButton togbtn;
private boolean isPaused = false;
private boolean isCanceled = false;
private long remainingTime = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.tv1);
period = (TextView) findViewById(R.id.period_number);
startbtn = (Button) findViewById(R.id.startBtn);
cancelbtn = (Button) findViewById(R.id.cancelBtn);
togbtn = (ToggleButton) findViewById(R.id.togBtn);
cancelbtn.setEnabled(false);
togbtn.setEnabled(false);
startbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
foulCounterA = 0;
foulCounterB = 0;
displayForTeamAFoul(foulCounterA);
displayForTeamBFoul(foulCounterB);
if (periodCount < 3)
periodCount = periodCount + 1;
else periodCount = 4;
period.setText("Period " + periodCount);
startbtn.setEnabled(false);
cancelbtn.setEnabled(true);
togbtn.setEnabled(true);
isPaused = false;
isCanceled = false;
long millisInFuture = 20000; /////20sec
long countDownInterval = 1000; /////1sec
new CountDownTimer(millisInFuture, countDownInterval) {
#Override
public void onTick(long millisUntilFinished) {
if (isPaused || isCanceled) {
cancel();
} else {
tv1.setText("" + millisUntilFinished / 1000);
remainingTime = millisUntilFinished;
}
}
#Override
public void onFinish() {
startbtn.setEnabled(true);
togbtn.setEnabled(false);
if (periodCount < 4)
tv1.setText("Times up!");
else tv1.setText("Game Over!");
}
}.start();
}
});
togbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (togbtn.isChecked()) {
isPaused = true;
} else {
isPaused = false;
long millisInFuture = remainingTime;
long countDownInterval = 1000; /////1sec
new CountDownTimer(millisInFuture, countDownInterval) {
#Override
public void onTick(long millisUntilFinished) {
if (isPaused || isCanceled) {
cancel();
} else {
tv1.setText("" + millisUntilFinished / 1000);
remainingTime = millisUntilFinished;
}
}
#Override
public void onFinish() {
startbtn.setEnabled(true);
togbtn.setEnabled(false);
if (periodCount < 4)
tv1.setText("Times up!");
else tv1.setText("Game Over!");
}
}.start();
}
}
});
cancelbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
isCanceled = true;
period.setText("Period");
tv1.setText("Timer");
startbtn.setEnabled(true);
togbtn.setEnabled(false);
cancelbtn.setEnabled(false);
foulCounterA = 0;
foulCounterB = 0;
periodCount = 0;
displayForTeamAFoul(foulCounterA);
displayForTeamBFoul(foulCounterB);
}
});
}
public void onePointForTeamA(View v) {
scoreTeamA = scoreTeamA + 1;
scoreOnePointTeamA = scoreOnePointTeamA + 1;
displayForTeamA(scoreTeamA);
displayForTeamAOnePoint(scoreOnePointTeamA);
}
public void foulCountForTeamA(View v) {
if (foulCounterA < 5)
foulCounterA = foulCounterA + 1;
else
foulCounterA = 5;
displayForTeamAFoul(foulCounterA);
}
public void displayForTeamAOnePoint(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score_1_point);
scoreView.setText(String.valueOf(score));
}
public void displayForTeamAFoul(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_foul);
scoreView.setText(String.valueOf(score));
}
}
I wanted to make the java code as simple as I can so I've just added the lines for my question. What I'm trying to do is
android:onClick="onePointForTeamA"make this button only clickable when foulCounterA = 5 Failed to add if (foulCounterA = 5); inside public void foulCountForTeamA(View v) {
It gave me an error that way. Says required: boolean, found: int.
What should I do with the code? Any help will be appreeciated
Regarding your concrete question, the syntax of if (foulCounterA = 5); is wrong, because the equation check is have to made by == operator.
So the correct syntax would be if (foulCounterA == 5);
As #OH GOD SPIDERS wrote in the comment, you should check the basics of java operators.
Also I recommend You to search for the answer before asking a new question.

[HELP]FATAL EXCEPTION: main java.lang.NullPointerException [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
ProductDatabase.ProductDatabaseHelper controller = new ProductDatabase.ProductDatabaseHelper(this);
EditText mBarcodeEdit;
EditText mFormatEdit;
EditText mTitleEdit;
EditText mPriceEdit;
private static final int ZBAR_SCANNER_REQUEST = 0;
private static final int ZBAR_QR_SCANNER_REQUEST = 1;
private static final ProductData mProductData = new ProductData();
Button mScanButton;
Button mAddButton;
Button mSelectButton;
Button mExportButton;
Button btnimport;
ProductDatabase mProductDb;
ListView ls;
TextView infotext;
File file = null;
// DatabaseHelper dbhelper = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ls = (ListView) findViewById(R.id.placeslist);
mBarcodeEdit = (EditText) findViewById(R.id.barcodeEdit);
mFormatEdit = (EditText) findViewById(R.id.codeFormatEdit);
mTitleEdit = (EditText) findViewById(R.id.titleEdit);
mPriceEdit = (EditText) findViewById(R.id.priceEdit);
mScanButton = (Button) findViewById(R.id.scan_btn);
mAddButton = (Button) findViewById(R.id.addButton);
mSelectButton = (Button) findViewById(R.id.selelctButton);
mProductDb = new ProductDatabase(this); // not yet shown
infotext = (TextView) findViewById(R.id.txtresulttext);
mExportButton = (Button) findViewById(R.id.exportbtn);
mSelectButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, product_list.class);
startActivity(i);
}
});
mAddButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String barcode = mBarcodeEdit.getText().toString();
String format = mFormatEdit.getText().toString();
String title = mTitleEdit.getText().toString();
String price = mPriceEdit.getText().toString();
String errors = validateFields(barcode, format, title, price);
if (errors.length() > 0) {
showInfoDialog(MainActivity.this, "Please fix errors", errors);
} else {
mProductData.barcode = barcode;
mProductData.format = format;
mProductData.title = title;
mProductData.price = new BigDecimal(price);
mProductDb.insert(mProductData);
showInfoDialog(MainActivity.this, "Success", "Product saved successfully");
resetForm();
}
}
});
mExportButton.setOnClickListener(new View.OnClickListener() {
SQLiteDatabase sqldb = controller.getReadableDatabase(); //My Database class
Cursor c =null;
#Override
public void onClick(View view) { //main code begins here
try {
c = sqldb.rawQuery("select * from spot_pay.db", null);
int rowcount = 0;
int colcount = 0;
File sdCardDir = Environment.getExternalStorageDirectory();
String filename = "MyBackUp.csv";
// the name of the file to export with
File saveFile = new File(sdCardDir, filename);
FileWriter fw = new FileWriter(saveFile);
BufferedWriter bw = new BufferedWriter(fw);
rowcount = c.getCount();
colcount = c.getColumnCount();
if (rowcount > 0) {
c.moveToFirst();
for (int i = 0; i < colcount; i++) {
if (i != colcount - 1) {
bw.write(c.getColumnName(i) + ",");
} else {
bw.write(c.getColumnName(i));
}
}
bw.newLine();
for (int i = 0; i < rowcount; i++) {
c.moveToPosition(i);
for (int j = 0; j < colcount; j++) {
if (j != colcount - 1)
bw.write(c.getString(j) + ",");
else
bw.write(c.getString(j));
}
bw.newLine();
}
bw.flush();
infotext.setText("Exported Successfully.");
}
} catch (Exception ex) {
if (sqldb.isOpen()) {
sqldb.close();
infotext.setText(ex.getMessage().toString());
}
} finally {
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
private void showInfoDialog(Context context, String title, String information) {
new AlertDialog.Builder(context)
.setMessage(information)
.setTitle(title)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
private void resetForm() {
// TODO Auto-generated method stub
mBarcodeEdit.getText().clear();
mFormatEdit.getText().clear();
mTitleEdit.getText().clear();
mPriceEdit.getText().clear();
}
public void launchScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public void launchQRScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public boolean isCameraAvailable() {
PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ZBAR_SCANNER_REQUEST:
case ZBAR_QR_SCANNER_REQUEST:
if (resultCode == RESULT_OK) {
mBarcodeEdit.setText(data.getStringExtra(ZBarConstants.SCAN_RESULT));
// Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED && data != null) {
String error = data.getStringExtra(ZBarConstants.ERROR_INFO);
if (!TextUtils.isEmpty(error)) {
Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
}
}
break;
}
}
private static String validateFields(String barcode, String format,
String title, String price) {
StringBuilder errors = new StringBuilder();
if (barcode.matches("^\\s*$")) {
errors.append("Barcode required\n");
}
if (format.matches("^\\s*$")) {
errors.append("Format required\n");
}
if (title.matches("^\\s*$")) {
errors.append("Title required\n");
}
if (!price.matches("^-?\\d+(.\\d+)?$")) {
errors.append("Need numeric price\n");
}
return errors.toString();
}
}
I think string may be null somewhere. Please type something in textfield or check for null string.

Global variable reset to 0

I have a global variable inext set to a random value correctly before a call to setWordsQuestion(). As soon as I enter setWordsQuestion() the value is 0. Do you know how I can debug this?
and reset to 0:
Here is the java file:
public class ExercisesWords_fragment extends Fragment {
static Context context;
String login;
String fileMenuCard = null;
InputStreamReader isr;
InputStream fIn;
BufferedReader input_card = null;
int level, lang;
int ihelp;
String fileLogin;
RadioGroup rg;
RadioButton rb1, rb2, rb3, rb4;
EditText edt;
TextView txt, question;
Button validation, next, help;
int MAXWORDS = 42;
String[] words_questions = new String[MAXWORDS];
String[] words_cb1 = new String[MAXWORDS];
String[] words_cb2 = new String[MAXWORDS];
String[] words_cb3 = new String[MAXWORDS];
String[] words_cb4 = new String[MAXWORDS];
String[] words_response = new String[MAXWORDS];
int[] words_level = new int[MAXWORDS];
int MAXTEMP = 5;
int[] tmp;
int inext_question, inext;
public ExercisesWords_fragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.exercises_words_fragment, container, false);
}
#Override
public void onAttach(Activity activity){
super.onAttach(activity);
}
#Override
public void onPause() {
closeFileWords();
super.onPause();
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
context = getActivity().getApplicationContext();
fileMenuCard = "words";
login = getArguments().getString("login");
lang = getArguments().getInt("lang");
level = getArguments().getInt("level");
fileLogin = login + "_words.txt";
initViewFind();
initExerciseWords();
nextWordsQuestion();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
edt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
validateResponse();
}
return false;
}
});
validation.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
validateResponse();
}
});
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
nextWordsQuestion();
}
});
help.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ihelp = 1;
hideKeyboard();
helpWords();
ihelp = 0;
}
});
}
private void drawBTN() {
if(lang == 0) {
validation.setText(R.string.pro_validation);
validation.setVisibility(View.VISIBLE);
next.setText(R.string.next);
next.setVisibility(View.VISIBLE);
help.setText(R.string.help);
help.setVisibility(View.VISIBLE);
}
else {
validation.setText(R.string.pro_validation_fr);
validation.setVisibility(View.VISIBLE);
next.setText(R.string.next_fr);
next.setVisibility(View.VISIBLE);
help.setText(R.string.help_fr);
help.setVisibility(View.VISIBLE);
}
}
private void nextWordsQuestion() {
int inext;
Random r;
r = new Random();
inext = r.nextInt(MAXWORDS);
if (inext_question < MAXTEMP) {
tmp[inext_question] = inext;
inext_question++;
setWordsQuestion();
return;
}
for (int i = 0; i < MAXTEMP; i++) {
if (inext == tmp[i]) {
r = new Random();
inext = r.nextInt(MAXWORDS);
i--;
}
}
System.arraycopy(tmp, 1, tmp, 0, MAXTEMP - 1);
tmp[MAXTEMP - 1] = inext;
setWordsQuestion();
}
private void setWordsQuestion(){
question.setText(words_questions[inext]);
question.setVisibility(View.VISIBLE);
edt.setText("");
rb1.setText(words_cb1[inext]);
rb2.setText(words_cb2[inext]);
rb3.setText(words_cb3[inext]);
rb4.setText(words_cb4[inext]);
rb1.setVisibility(View.INVISIBLE);
rb2.setVisibility(View.INVISIBLE);
rb3.setVisibility(View.INVISIBLE);
rb4.setVisibility(View.INVISIBLE);
rg.clearCheck();
hideKeyboard();
}
private void validateResponse(){
String response;
if(ihelp == 1){
int sel = rg.getCheckedRadioButtonId();
if(sel < 0) return;
RadioButton rb = (RadioButton) getActivity().findViewById(sel);
response = rb.getText().toString();
}
else {
response = edt.getText().toString();
}
TextView resp = (TextView) getActivity().findViewById(R.id.resp_words);
if(response.equals(words_response[inext])) {
next.setTextColor(Color.GREEN);
next.setVisibility(View.VISIBLE);
resp.setText(R.string.resp_card);
resp.setTextColor(Color.GREEN);
resp.setVisibility(View.VISIBLE);
}
else {
resp.setText(R.string.resp_card_no);
resp.setTextColor(Color.RED);
resp.setVisibility(View.VISIBLE);
}
}
private void helpWords(){
hideKeyboard();
rb1.setText(words_cb1[inext]);
rb1.setVisibility(View.VISIBLE);
rb2.setText(words_cb2[inext]);
rb2.setVisibility(View.VISIBLE);
rb3.setText(words_cb3[inext]);
rb3.setVisibility(View.VISIBLE);
rb4.setText(words_cb4[inext]);
rb4.setVisibility(View.VISIBLE);
}
private void hideKeyboard(){
EditText e = (EditText) getActivity().findViewById(R.id.words_answer);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(e.getWindowToken(), 0);
}
private void openWords(){
String l = null;
try {
if (lang == 0)
fIn = context.getResources().getAssets()
.open(fileMenuCard+".txt", Context.MODE_PRIVATE);
else
fIn = context.getResources().getAssets()
.open(fileMenuCard+"_fr.txt", Context.MODE_PRIVATE);
isr = new InputStreamReader(fIn);
input_card = new BufferedReader(isr);
} catch (Exception e) {
e.getMessage();
}
for(int i=0;i<MAXWORDS;i++){
try {
l = input_card.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (l != null) {
StringTokenizer tokens = new StringTokenizer(l, ";");
words_questions[i] = tokens.nextToken();
words_level[i] = Integer.valueOf(tokens.nextToken());
words_cb1[i] = tokens.nextToken();
words_cb2[i] = tokens.nextToken();
words_cb3[i] = tokens.nextToken();
words_cb4[i] = tokens.nextToken();
words_response[i] = tokens.nextToken();
}
}
}
private void closeFileWords(){
try {
fIn.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
isr.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
input_card.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void initExerciseWords(){
tmp = new int[MAXTEMP];
for(int i=0;i<MAXTEMP;i++)
tmp[i] = -1;
inext_question = 0;
openWords();
}
private void initViewFind(){
edt = (EditText) getActivity().findViewById(R.id.words_answer);
txt = (TextView) getActivity().findViewById(R.id.title_words);
validation = (Button) getActivity().findViewById(R.id.validation_words);
next = (Button) getActivity().findViewById(R.id.next_words);
help = (Button) getActivity().findViewById(R.id.help_words);
question = (TextView) getActivity().findViewById(R.id.words_question);
rg = (RadioGroup) getActivity().findViewById(R.id.rg_words);
rb1 = (RadioButton) getActivity().findViewById(R.id.radio1_words);
rb2 = (RadioButton) getActivity().findViewById(R.id.radio2_words);
rb3 = (RadioButton) getActivity().findViewById(R.id.radio3_words);
rb4 = (RadioButton) getActivity().findViewById(R.id.radio4_words);
if(lang == 0)
txt.setText(R.string.words_fr);
else
txt.setText(R.string.words_title_fr);
}
}
You are setting a local variable that hides the instance member :
private void nextWordsQuestion() {
int inext; // remove this line
...
inext = r.nextInt(MAXWORDS);
...
setWordsQuestion();
...
}
Therefore setWordsQuestion, which uses the instance member, doesn't see the value you set in nextWordsQuestion.
When you assign a random value to inext, you are assigning it to a local variable, not the global one.
To fix, simply remove the local variable.
private void nextWordsQuestion() {
//int inext;
Random r;
r = new Random();
inext = r.nextInt(MAXWORDS);
if (inext_question < MAXTEMP) {
tmp[inext_question] = inext;
inext_question++;
setWordsQuestion();
return;
}

Error while working in Android Studio

This is an application coding for a basic calculator using Android Studio. There is en error just before the end of the coding. I have mentioned the error in the coding directly.
Can some please explain what the error is all about and how I can go about rectifying the same?
package com.example.asish.calculator;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Button bone, btwo, bthree, bfour, bfive, bsix, bseven, beight, bnine, bzero, badd, bsub, bmul, bdiv, bclear,
bce, bequal;
TextView txt;
String s = "", s1 = "", s2 = "", s3 = "";
int i = 0, i1 = 0, c = -1, flag_disable = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bone = (Button) findViewById(R.id.one);
btwo = (Button) findViewById(R.id.two);
bthree = (Button) findViewById(R.id.three);
bfour = (Button) findViewById(R.id.four);
bfive = (Button) findViewById(R.id.five);
bsix = (Button) findViewById(R.id.six);
bseven = (Button) findViewById(R.id.seven);
beight = (Button) findViewById(R.id.eight);
bnine = (Button) findViewById(R.id.nine);
bzero = (Button) findViewById(R.id.zero);
bce = (Button) findViewById(R.id.ce);
bequal = (Button) findViewById(R.id.equals);
bclear = (Button) findViewById(R.id.clear);
badd = (Button) findViewById(R.id.plus);
bsub = (Button) findViewById(R.id.minus);
bdiv = (Button) findViewById(R.id.division);
bmul = (Button) findViewById(R.id.multiply);
bone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"1");
s = "";
}
});
btwo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"2");
s = "";
}
});
bthree.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"3");
s = "";
}
});
bfour.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"4");
s = "";
}
});
bfive.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"5");
s = "";
}
});
bsix.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"6");
s = "";
}
});
bseven.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"7");
s = "";
}
});
beight.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"8");
s = "";
}
});
bnine.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+9);
s = "";
}
});
bzero.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s+"0");
s = "";
}
});
badd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if(!tmp.equals("+")&&!tmp.equals("-")&&!tmp.equals("*")&&!tmp.equals("/"))
s1=tmp;
c=0;
txt.setText("+");
}
});
bsub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if(!tmp.equals("+")&&!tmp.equals("-")&&!tmp.equals("*")&&!tmp.equals("/"))
s1=tmp;
c=2;
txt.setText("-");
}
});
bmul.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if(!tmp.equals("+")&&!tmp.equals("-")&&!tmp.equals("*")&&!tmp.equals("/"))
s1=tmp;
c=3;
txt.setText("*");
}
});
bdiv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if(!tmp.equals("+")&&!tmp.equals("-")&&!tmp.equals("*")&&!tmp.equals("/"))
s1=tmp;
c=2;
txt.setText("/");
}
});
bequal.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(s1=="+"||s1=="-"||s1=="/"||s1=="*") {
i = 0;
}
else if(s1==null|| s1==""||s1.trim().length()==0) {
i = i;
}
else {
i = Integer.parseInt(s1);
}
s2 = (String) txt.getText();
if(s2=="+"||s2=="-"||s2=="/"||s2=="*") {
i1 = 0;
}
else if(s2==null|| s2==""||s2.trim().length()==0) {
i1 = 0;
}
else {
i1 = Integer.parseInt(s2);
}
if(c==0) {
i = i + i1;
}
else if(c==1) {
i = i - i1;
}
else if(c==2){
if(i1==0) {
Toast.makeText(getApplicationContext(), "Invalid Input", Toast.LENGTH_LONG).show();
i = 0;
}
else{
i = i / i1;
}
}
else if(c==3) {
i = i * i1;
}
else {
i = 0;
}
txt.setText(i+"");
}
});
bclear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*") || s.equals("")) {
i = 0;
} else {
i = Integer.parseInt(s);
i = i / 10;
}
if (i == 0) {
txt.setText("");
} else {
txt.setText(i + "");
}
s = null;
}
});
bce.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txt.setText("");
i = 0;
i1 = 0;
s1 = "";
s2 = "";
c = -1;
}
});
}
} --> Error in this line. Error message - Class or interface expected.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Looks like you have to delete one of the brackets where you noted the error. That should fix the issue.
Try this code to your tool.
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.vcs.YOURPACKAGE.R;(it will be import automatically)
public class MainActivity extends AppCompatActivity {
Button bone, btwo, bthree, bfour, bfive, bsix, bseven, beight, bnine, bzero, badd, bsub, bmul, bdiv, bclear,
bce, bequal;
TextView txt;
String s = "", s1 = "", s2 = "", s3 = "";
int i = 0, i1 = 0, c = -1, flag_disable = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bone = (Button) findViewById(R.id.one);
btwo = (Button) findViewById(R.id.two);
bthree = (Button) findViewById(R.id.three);
bfour = (Button) findViewById(R.id.four);
bfive = (Button) findViewById(R.id.five);
bsix = (Button) findViewById(R.id.six);
bseven = (Button) findViewById(R.id.seven);
beight = (Button) findViewById(R.id.eight);
bnine = (Button) findViewById(R.id.nine);
bzero = (Button) findViewById(R.id.zero);
bce = (Button) findViewById(R.id.ce);
bequal = (Button) findViewById(R.id.equals);
bclear = (Button) findViewById(R.id.clear);
badd = (Button) findViewById(R.id.plus);
bsub = (Button) findViewById(R.id.minus);
bdiv = (Button) findViewById(R.id.division);
bmul = (Button) findViewById(R.id.multiply);
bone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "1");
s = "";
}
});
btwo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "2");
s = "";
}
});
bthree.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "3");
s = "";
}
});
bfour.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "4");
s = "";
}
});
bfive.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "5");
s = "";
}
});
bsix.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "6");
s = "";
}
});
bseven.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "7");
s = "";
}
});
beight.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "8");
s = "";
}
});
bnine.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + 9);
s = "";
}
});
bzero.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*")) {
txt.setText("");
s = "";
}
txt.setText(s + "0");
s = "";
}
});
badd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if (!tmp.equals("+") && !tmp.equals("-") && !tmp.equals("*") && !tmp.equals("/"))
s1 = tmp;
c = 0;
txt.setText("+");
}
});
bsub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if (!tmp.equals("+") && !tmp.equals("-") && !tmp.equals("*") && !tmp.equals("/"))
s1 = tmp;
c = 2;
txt.setText("-");
}
});
bmul.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if (!tmp.equals("+") && !tmp.equals("-") && !tmp.equals("*") && !tmp.equals("/"))
s1 = tmp;
c = 3;
txt.setText("*");
}
});
bdiv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tmp = (String) txt.getText();
if (!tmp.equals("+") && !tmp.equals("-") && !tmp.equals("*") && !tmp.equals("/"))
s1 = tmp;
c = 2;
txt.setText("/");
}
});
bequal.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (s1 == "+" || s1 == "-" || s1 == "/" || s1 == "*") {
i = 0;
} else if (s1 == null || s1 == "" || s1.trim().length() == 0) {
i = i;
} else {
i = Integer.parseInt(s1);
}
s2 = (String) txt.getText();
if (s2 == "+" || s2 == "-" || s2 == "/" || s2 == "*") {
i1 = 0;
} else if (s2 == null || s2 == "" || s2.trim().length() == 0) {
i1 = 0;
} else {
i1 = Integer.parseInt(s2);
}
if (c == 0) {
i = i + i1;
} else if (c == 1) {
i = i - i1;
} else if (c == 2) {
if (i1 == 0) {
Toast.makeText(getApplicationContext(), "Invalid Input", Toast.LENGTH_LONG).show();
i = 0;
} else {
i = i / i1;
}
} else if (c == 3) {
i = i * i1;
} else {
i = 0;
}
txt.setText(i + "");
}
});
bclear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
s = (String) txt.getText();
if (s.equals("+") || s.equals("-") || s.equals("/") || s.equals("*") || s.equals("")) {
i = 0;
} else {
i = Integer.parseInt(s);
i = i / 10;
}
if (i == 0) {
txt.setText("");
} else {
txt.setText(i + "");
}
s = null;
}
});
bce.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txt.setText("");
i = 0;
i1 = 0;
s1 = "";
s2 = "";
c = -1;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Categories