Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid buttons aren't changing the textfield they're supposed to edit
    primarykey
    data
    text
    <p>I'm designing a simple app to count the rows and stitches in crocheting/knitting, but I'm having issues. The actual counting itself is just a modified calculator: display a text field that holds the current number of stitches, and buttons which allow you to add or subtract 1, 5 or 10 to the count. Problem is, punching the buttons in the emulator doesn't work -- the thing compiles without issues and builds without issues, so I'm thinking it's something small I've (not) done.</p> <p>My Main file:</p> <pre><code>public class mainCount extends Activity { private EditText Scr; //Textbox screen private int NumberBF; //saves screen before pressing button operations private String Operation; private ButtonClickListener btnClick; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Scr = (EditText) findViewById(R.id.stitchCount); int idList[] = {R.id.stitchMin1, R.id.stitchMin5, R.id.stitchMin10, R.id.stitchPlus1, R.id.stitchPlus5, R.id.stitchPlus10, R.id.clearButton}; for(int id:idList){ View v; v = (View) findViewById(id); v.setOnClickListener(btnClick); } } @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_count, menu); return true; } public void mMath(String str){ NumberBF = Integer.parseInt(Scr.getText().toString()); Operation = str; Scr.setText("0"); } private void getKeyboard(String str){ String ScrCurrent = Scr.getText().toString(); if(ScrCurrent.equals("0")) ScrCurrent = ""; ScrCurrent += str; Scr.setText(ScrCurrent); } public void mResult(String str){ int NumAf = Integer.parseInt(Scr.getText().toString()); int result = 0; if(str.equals("+1")){ result = NumAf + 1; } if(str.equals("+5")){ result = NumAf + 5; } if(str.equals("+10")){ result = NumAf + 10; } if(str.equals("-1")){ result = NumAf - 1; } if(str.equals("-5")){ result = NumAf - 5; } if(str.equals("-10")){ result = NumAf - 10; } Scr.setText(String.valueOf(result)); } // ButtonListener class private class ButtonClickListener implements View.OnClickListener{ public void onClick(View v) { switch (v.getId()) { case R.id.clearButton: //Clears stitches for this row Scr.setText("0"); NumberBF = 0; Operation = ""; break; case R.id.stitchPlus1: Operation = "+1"; mResult(Operation); break; case R.id.stitchPlus5: Operation = "+5"; mResult(Operation); break; case R.id.stitchPlus10: Operation = "+10"; mResult(Operation); break; case R.id.stitchMin1: Operation = "-1"; mResult(Operation); break; case R.id.stitchMin5: Operation = "-5"; mResult(Operation); break; case R.id.stitchMin10: Operation = "-10"; mResult(Operation); break; default: String numb = ((Button) v).getText().toString(); getKeyboard(numb); break; } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload