I'm trying to make a simple matched pairs app. The app starts with all TextViews having "#" as a text. When I press a text field, it changes to a letter which was stored for that field.
Anyway, I want to open two fields (I mean to change their strings) and compare them. If they are equal, they remain "opened" with new letters (e.g. both are "A"). In the case with equal letters, everything works fine, but I have difficulties when the letters differ.
If they are not equal, I want to make them to show themselves with new text for one second and after that to go to the previous sign (i.e. "#"). When I press the first field, it changes its text but when I go for the second field and if their stored letters are not equal, the second field doesn't change the text and the text from the first field goes back to the previous sign.
What do I need to do to show fields with new text for a short period of time if their Strings are not equal?
This is how my table looks:
public class MainActivity extends AppCompatActivity {
TextView textView;
int counterForPressedFields= 0;
int textViewForComparationCounter = 0;
TextView firstTextViewForComparation;
TextView secondTextViewForComparation;
int[] nonPressedFields= {1, 1, 1, 1};
int pressedField = 2;
int tag = 0;
public void show(View view) throws InterruptedException {
textView = (TextView) view;
tag = Integer.parseInt(textView.getTag().toString());
if (nonPressedFields[tag] == 1) {
nonPressedFields[tag] = pressedField;
if (counterForPressedFields< 2) {
textViewForComparationCounter += 1;
counterForPressedFields+= 1;
switch (tag) {
case 0:
textView = (TextView) findViewById(R.id.front1);
textView.setText("A");
break;
case 1:
textView = (TextView) findViewById(R.id.front2);
textView.setText("B");
break;
case 2:
textView = (TextView) findViewById(R.id.front3);
textView.setText("A");
break;
case 3:
textView = (TextView) findViewById(R.id.front4);
textView.setText("B");
break;
}
if (textViewForComparationCounter == 1) {
firstTextViewForComparation = (TextView) view;
firstTextViewForComparation = textView;
} else if (textViewForComparationCounter == 2) {
secondTextViewForComparation= (TextView) view;
secondTextViewForComparation= textView;
}
}
if(counterForPressedFields == 2){
if(firstTextViewForComparation.getText().toString().equals(secondTextViewForComparation.getText().toString())){
counterForPressedFields= 0;
textViewForComparationCounter = 0;
}else{
firstTextViewForComparation.setText("#");
secondTextViewForComparation.setText("#");
nonPressedFields[Integer.parseInt(firstTextViewForComparation.getTag().toString())] = 1;
nonPressedFields[Integer.parseInt(secondTextViewForComparation.getTag().toString())] = 1;
counterForPressedFields= 0;
textViewForComparationCounter = 0;
}
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Try using a handler. You can update your textViews back to "#" with its postDelayed method.
private final Handler handler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
//update your textViews here
}
};
handler.postDelayed(runnable, millisecondsOfDelay);
Hope it helps!
Related
I made a TableLayout 3x3 in "Activity A"(Chose a Table Layout, because I thought it suits my needs)
7 of the 9 cells are clickable and open "Activity B" which is a custom number picker I made.
I used an intent to pass an array and other data to activiy B
The idea of my number picker is to set a value in the cell I just clicked in Activiy A(I wanted something like the calendarDatePicker)
In "Activity B" I have a method to update the values from "Activity A" and finish() "Activity B" when an image View is clicked wich works very fine except that it does not set the value for the clicked Text View
How can I set the TextValue from another activity when the TextValue is contained in a Table Layout?
I don't use intent, because honestly I don't know how to handle it when the "Activity B" is closed.
I mean where in "Activity A" should I handle this intent from "Activity B"
Using the debugger I found out that trying to set the text using the TextView Id does not works as it shows a "null" object in the debugger.
Activiy A
package com.example.racu.threebythree;
public class threebythree extends AppCompatActivity {
public static ArrayList<Integer> ColumnA = new ArrayList<Integer>();
public static ArrayList<Integer> ColumnB = new ArrayList<Integer>();
public static ArrayList<Integer> ColumnC = new ArrayList<Integer>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three_by_three);
for (int i = 1; i < 28; i++) {
if (i > 0 && i < 10)
ColumnA.add(i);
if (i > 10 && i < 19)
ColumnB.add(i);
if (i > 19 && i < 28)
ColumnC.add(i);
}
}
public void openNumberPicker(View v) {
// I used this to "guess" the location of the cell in the table layout as I could not find a way to do it.
String cellName = v.getResources().getResourceName(v.getId());
String cellLetter = cellName.substring(cellName.lastIndexOf("/") + 1);
// Send intent
Intent intent = new Intent(this, NumberPicker.class);
intent.putExtra("Id", (cellLetter.substring(0, 1) + cellLetter.substring(2)).toUpperCase());
switch (cellLetter.substring(0, 1)) {
case ("a"):
intent.putIntegerArrayListExtra("Column", ColumnA);
break;
case ("b"):
intent.putIntegerArrayListExtra("Column", ColumnB);
break;
case ("c"):
intent.putIntegerArrayListExtra("Column", ColumnC);
break;
}
intent.putExtra("Cell ID", v.getId());
startActivity(intent);
}
}
Avtivity B
package com.example.racu.threebythree;
public class NumberPicker extends AppCompatActivity {
GridView numberPicker;
ArrayList<Integer> numbersToDisplay;
TextView viewToDisplay;
ImageView ok, cancel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_number_picker);
numberPicker = (GridView) findViewById(R.id.arrayNumbers);
viewToDisplay = (TextView) findViewById(R.id.number_to_select);
ok = (ImageView) findViewById(R.id.add_number_to_card);
ok.setClickable(false);
Intent intent = getIntent();
String idFromIntent = intent.getStringExtra("Id");
numbersToDisplay = intent.getIntegerArrayListExtra("Letter");
TextView numberPosition = (TextView) findViewById(R.id.numberPosition);
numberPosition.setText(idFromIntent);
final TextView chosenNumber = (TextView) findViewById(R.id.chosenNumber);
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this, R.layout.number_for_picker, numbersToDisplay);
numberPicker.setAdapter(adapter);
numberPicker.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
chosenNumber.setText(((TextView) v).getText());
ok.setImageResource(R.drawable.ok_blue);
ok.setClickable(true);
}
});
}
public void updateThreByThree(View v) {
Intent intent = getIntent();
int currentCell = intent.getIntExtra("Cell ID", 0);
String idFromIntent = intent.getStringExtra("Id").substring(0, 1);
TextView chosenNumber = (TextView) findViewById(R.id.chosenNumber);
// Here I try to Set the text to the cell in Activity A, using its R.id, but in the debugger I get a null reference, therefore my app crashes
TextView currentCellToEdit = (TextView) findViewById(currentCell);
currentCellToEdit.setText(chosenNumber.getText());
int temp = Integer.parseInt(chosenNumber.getText().toString());
switch (idFromIntent) {
case "A":
threebythree.ColumnA.remove(Integer.valueOf(temp));
break;
case "B":
threebythree.ColumnB.remove(Integer.valueOf(temp));
break;
case "C":
threebythree.ColumnC.remove(Integer.valueOf(temp));
break;
}
finish();
}
public void cancel(View view) {
finish();
}
}
Thanks to Pavan for the hint I found two more very helpful post here and this one was EXACTLY what I was looking for.
Like that ( make sure you give the TableLayout an id ):
TableLayout tl = (TableLayout)findViewById( R.id.tableLayout );
TextView tv = (TextView)tl.findViewById( R.id.textView );
change the text of the button once clicked to P then again that same button is clicked the text should change to A then again the same button is clicked the text should change to H then again when the button is pressed the text should change to L in android Studio how c
final Button button = (Button) findViewById(R.id.number);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
switch (curr) {
case 0:
button.setText("P");
curr = curr + 1;
break;
case 1:
button.setText("A");
curr = curr + 1;
break;
case 2:
button.setText("H");
curr = curr + 1;
break;
case 3:
button.setText("L");
curr = 0;
break;
}
}
});
This will work 100%
public class MainActivity extends AppCompatActivity {
private int current = 0;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (current){
case 0:
button.setText("P");
current = 1;
break;
case 1:
button.setText("A");
current = 2;
break;
case 2:
button.setText("H");
current = 3;
break;
case 3:
button.setText("L");
current = 0;
break;
}
}
});
}
}
You're going to need three things for this:
A way to react to the button being clicked
A way to set and get the state of the button
A way to change the text on the button
Thankfully, these are all easy tasks.
To react to a button click, set its OnClickListener
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
updateButtonState();
}
});
To set and get the state of the button, we need a way of representing the state. Since you described a simple state of P -> A -> H -> L we can represent each point as an integer.
final int BUTTON_STATE_P = 0;
final int BUTTON_STATE_A = 1;
final int BUTTON_STATE_H = 2;
final int BUTTON_STATE_L = 3;
We can then simply store the given state into a variable change this variable according to our state logic and then read whatever value the variable is at.
int buttonState = BUTTON_STATE_P;
private void updateButtonState(){
if (buttonState == BUTTON_STATE_P){
buttonState = BUTTON_STATE_A;
}
else if (buttonState == BUTTON_STATE_A){
buttonState = BUTTON_STATE_H;
}
else if (buttonState == BUTTON_STATE_H){
buttonState = BUTTON_STATE_L;
}
}
Then we just need a way of setting the text of the button depending upon what state we're in. To do this we need to know what each state looks like in terms of text.
button.setText(getTextForButtonState(buttonState));
private String getTextForButtonState(int buttonState){
if (buttonState == BUTTON_STATE_P){
return "P";
}
else if (buttonState == BUTTON_STATE_A){
return "A";
}
else if (buttonState == BUTTON_STATE_H){
return "H";
}
else if (buttonState == BUTTON_STATE_L){
return "L";
}
return null;
}
You'll notice that the most important step was step 2. You can make lots of different decisions as to how you might want to handle a state. You might decide that you want to put all of your state code into its own class and then just call methods of that class, as one suggestion.
Hope this helps.
I hope this isn't a stupid question. I'm having some trouble clearing a TextView. I've looked around and everyone keeps saying use: textView.setText(""); in onCreate but doesn't seem to work for some reason. Basically, my app just accepts a number from an editText then runs the Fibonacci sequence (when a button is clicked) and displays the result in a textView. Well, the sequence displays fine but I want the textview to clear every time I click the button - so far it just keeps adding more text to what's already there.
Am I placing textView.setText(""); in the wrong location? Or am I just missing some other concept? (I also tried placing it from my OnClick - that didn't work either).
Here is my code:
public class MainActivity extends Activity {
// primary widgets
private EditText editText;
private TextView textView;
private Button button1;
static ArrayList<Integer> fibList = new ArrayList<Integer>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText1);
textView = (TextView) findViewById(R.id.textView2);
button1 = (Button) findViewById(R.id.button1);
//Attempt to clear TextView
textView.setText("");
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String input = editText.getText().toString();
int number = Integer.parseInt(input);
int tmp = 0;
// confirm input
if (number < 20) {
Toast.makeText(getApplicationContext(),
"You entered: " + number, Toast.LENGTH_LONG).show();
for (int i = 0; i <= number; i++) {
fibList.add(fib(i));
// sum even numbers
if (fib(i) % 2 == 0) {
tmp += fib(i);
}
}
} else {
Toast.makeText(getApplicationContext(),
"Number is too Large: " + number, Toast.LENGTH_LONG)
.show();
}
String array = fibList.toString();
textView.setText(array);
}
});
}
// run fibonacci sequence
public static int fib(int n) {
if (n < 2) {
return n;
} else {
return fib(n - 1) + fib(n - 2);
}
}
#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;
}
}
If you want the TextView to clear on each button click then the .setText must go in you onClick. The reason you would put the .setText in your onCreate is to clear the text as soon as your activity is created, but you do not have anything to clear just yet since your button has not yet been pushed so setText will do nothing. Also, since your onCreate will only run once for your activity, it will never go back to the setText again. Try the following:
public class MainActivity extends Activity {
// primary widgets
private EditText editText;
private TextView textView;
private Button button1;
static ArrayList<Integer> fibList = new ArrayList<Integer>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText1);
textView = (TextView) findViewById(R.id.textView2);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(""); //Clear the TextView
fibList.clear(); //Clear your array list before adding new elements
String input = editText.getText().toString();
int number = Integer.parseInt(input);
int tmp = 0;
// confirm input
if (number < 20) {
Toast.makeText(getApplicationContext(),
"You entered: " + number, Toast.LENGTH_LONG).show();
for (int i = 0; i <= number; i++) {
fibList.add(fib(i));
// sum even numbers
if (fib(i) % 2 == 0) {
tmp += fib(i);
}
}
} else {
Toast.makeText(getApplicationContext(),
"Number is too Large: " + number, Toast.LENGTH_LONG)
.show();
}
String array = fibList.toString();
textView.setText(array);
}
});
}
// run fibonacci sequence
public static int fib(int n) {
if (n < 2) {
return n;
} else {
return fib(n - 1) + fib(n - 2);
}
}
#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;
}
}
you will need to clear textView on Button click event before adding new results to it.do it as:
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(""); //<<<<<< clear TextView on Button Click
.....
The problem is more likely in fibList that is not being cleared
This code creates a seekbar and makes the seekbar create as many EditText fields as the slider is at / remove ones that would be too much. This code is in OnActivityCreated
final LinearLayout linearLayout = (LinearLayout) getActivity()
.findViewById(R.id.npv_calcfields);
EditText editText = new EditText(getActivity());
editText.setId(i);
editText.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
SeekBar bar = (SeekBar) getActivity().findViewById(R.id.npv_seekbar);
final TextView selection = (TextView) getActivity()
.findViewById(R.id.npv_selected);
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekbar, int progress,
boolean fromUser) {
selection.setText("You have selected " + progress + " periods.");
if (progress == 0) {
String normalstring = getActivity().getResources()
.getString(R.string.npv1);
selection.setText(normalstring);
}
if (i > progress) {
while (i > progress) {
i--;
EditText editText = (EditText) getActivity()
.findViewById(i);
linearLayout.removeView(editText);
}
} else {
while (i < progress) {
EditText editText = new EditText(getActivity());
editText.setId(i);
editText.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
linearLayout.addView(editText);
editText.setHint("Cash Flow " + i);
i++;
}
}
}
public void onStopTrackingTouch(SeekBar arg0) {
}
public void onStartTrackingTouch(SeekBar arg0) {
}
});
This code is in the general class area:
int i = 0;
EditText r = (EditText) getActivity().findViewById(R.id.npv_rate);
Button calc = (Button) getActivity().findViewById(R.id.npv_calc);
EditText[] DynamicField = new EditText[16];
Now I want users to input numbers into those edittext fields and then I want to do some math on them: Entry / (Math.pow(1+r, i) with i beeing the id of the field. The first entry should therefore be calculated as this: entry/(1+r)^0. This is what I tried but it doesn't work. It just crashes on startup.
calc.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Double r1 = Double.parseDouble(r.getText().toString());
EditText editText = (EditText) getActivity().findViewById(i);
TextView answer = (TextView) getActivity().findViewById(R.id.npv_answer);
double[] CashFlows;
CashFlows = new double[i];
double result = 0;
CashFlows[i] = (Double.parseDouble(editText.getText()
.toString())) / (Math.pow(1 + r1, i));
for (double d : CashFlows) {
result += d;
}
answer.setText("answer is " + result);
}
});
What did I do wrong? by the way only the last code segment isnt working. if i comment that out it all works fine i tested it :) just dosent do anything obviuosly :)
ok a little background on the errorlog that you can see here: http://pastebin.com/G8iX6Pkm
EDIT: the entire class file can be seen here: http://pastebin.com/dxA91dst, the entire project can be found here: https://github.com/killerpixler/Android-Financial-Calculator.git
the class file is a fragment that gets loaded in a DetailsActivity when somebody clicks on a listitem from the Main activity. Like i said the error has to be in the button listener because it was working before i added it.
That NullPointerException comes from the fact that you initialize your Views using the getActivity() method where you declare them as fields in the F_NPV class. The method getActivity() method will return a valid Activity reference after the callback onAttach() is called, so the way you initialize the views will not work as, at that moment(when the fields of the Fragment class are initialized) the method getActivity will return null, no valid reference. The correct way to do that initialization is doing it in the onActivityCreated callback:
EditText r;
Button calc;
//...
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
r = (EditText) getActivity().findViewById(R.id.npv_rate);
calc = (Button) getActivity().findViewById(R.id.npv_calc);
//...
Also, if I may, some suggestions regarding your code:
You're doing some double's parsing from Strings and it may be a good idea to check the input so you don't throw a NumberFormatException. For example, if the user creates some EditTexts and then clicks the calculate Button(I know, it sounds silly, but there are chances the user will do it(I did it for example)), you'll throw a NumberFormatException as you try to parse an empty String. Instead make a little check:
public void onClick(View arg0) {
Double r1 = Double.parseDouble((r.getText().toString())
.equals("") ? "0" : r.getText().toString());
EditText editText = (EditText) getActivity().findViewById(i);
TextView answer = (TextView) getActivity().findViewById(R.id.npv_answer);
double[] CashFlows;
CashFlows = new double[i];
double result = 0;
String tmp = editText.getText().toString();
CashFlows[i] = (Double.parseDouble(tmp.equals("") ? "0" : tmp))
/ (Math.pow(1 + r1, i));
//...
Also, even if you have correct values in the EditText the above code will throw a NullPointerException, as the editText variable will be null. The reason for this is in the while loops that you used to create the fields. For example, if the user moves the SeekBar to 3 than the while loop will run 3 times, each time incrementing the i value. So i will be 0, 1, 2, so far correct but because you increment i each time the final i will be 4. Now in the onClick method you'll look for an EditText with the id i, but as there is no EditText in the layout with the id 4, the view will be null.
Also, try to give your classes better names, you may know very well what they mean but you could be making things worse for someone that reads your code(like F_PNV, F_PV etc).
Code for the onActivityCreated method. This should solve what you're trying to do(if I understand what you want):
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
r = (EditText) getActivity().findViewById(R.id.npv_rate);
calc = (Button) getActivity().findViewById(R.id.npv_calc);
final LinearLayout linearLayout = (LinearLayout) getActivity()
.findViewById(R.id.npv_calcfields);
SeekBar bar = (SeekBar) getActivity().findViewById(R.id.npv_seekbar);
final TextView selection = (TextView) getActivity().findViewById(
R.id.npv_selected);
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekbar, int progress,
boolean fromUser) {
selection
.setText("You have selected " + progress + " periods.");
if (progress == 0) {
String normalstring = getActivity().getResources()
.getString(R.string.npv1);
selection.setText(normalstring);
linearLayout.removeAllViews(); // the progress is 0 so
// remove all the views that
// are currently present
} else {
int currentChilds = linearLayout.getChildCount();
if (currentChilds < progress) {
while (currentChilds != progress) {
EditText editText = new EditText(getActivity());
editText.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
linearLayout.addView(editText);
currentChilds++;
}
} else if (currentChilds > progress) {
while (currentChilds != progress) {
linearLayout.removeViewAt(linearLayout
.getChildCount() - 1);
currentChilds--;
}
}
}
}
public void onStopTrackingTouch(SeekBar arg0) {
}
public void onStartTrackingTouch(SeekBar arg0) {
}
});
calc.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Double r1 = Double.parseDouble((r.getText().toString())
.equals("") ? "0" : r.getText().toString());
TextView answer = (TextView) getActivity().findViewById(
R.id.npv_answer);
final LinearLayout linearLayout = (LinearLayout) getActivity()
.findViewById(R.id.npv_calcfields);
int size = linearLayout.getChildCount();
double[] CashFlows = new double[size];
double result = 0;
for (int i = 0; i < size; i++) {
EditText editText = (EditText) linearLayout.getChildAt(i);
String tmp = editText.getText().toString();
CashFlows[i] = (Double.parseDouble(tmp.equals("") ? "0"
: tmp)) / (Math.pow(1 + r1, i));
}
for (double d : CashFlows) {
result += d;
}
answer.setText("answer is " + result);
}
});
}
I am doing an application in which I have to display the numbers on TextView randomly and automatically with the help of Timer. I am able to get the random Numbers in the log without repeating, but I am not able to print the same on device please help me...
Regards,
Akki
Source:
//RandomNumber.java
public class RandomNumber extends Activity{
static Random randGen = new Random();
int tambolanum,count=0;
private Button previousbutton;
private Button startbutton;
private Button nextbutton;
int bingonum[]=new int[90];
boolean fill;
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.numbers);
LinearLayout number=(LinearLayout)findViewById(R.id.numbersview);
final TextView randomnum=(TextView)findViewById(R.id.numberstext);
previousbutton=(Button)findViewById(R.id.previous);
nextbutton=(Button)findViewById(R.id.next);
startbutton=(Button)findViewById(R.id.start);
startbutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on click
//--- Initialize the array to the ints 0-90
do{
fill = true;
//Get new random number
tambolanum = randGen.nextInt(90) + 1;
//If the number exists in the array already, don't add it again
for(int i = 0; i < bingonum.length; i++)
{
if(bingonum == tambolanum)
{
fill = false;
}
}
//If the number didn't already exist, put it in the array and move
//To the next position
if(fill == true)
{
bingonum[count] = tambolanum;
count++;
}
} while(count < 90);
for(i=0;i
{
randomnum.setText(Integer.toString(bingonum[i]);
}
}
setText(CharSequence text)
The problem you're having is that you're overwriting your text in every itteration of this loop:
for(i=0;i
{
randomnum.setText(Integer.toString(bingonum[i]);
}
You need to build your string first then set it. Something like:
StringBuilder sb = new StringBuilder();
for(i=0;i /* where's the rest of this for-statement? */
{
sb.append(Integer.toString(bingonum[i]);
}
randomnum.setText(sb.toString());