I'm trying to implement something in my Android application along these lines:
On any certain day if a user opens the app then they click a button, which will increment a number +1. Then can also click that button again which will put the number back to what it was so the number -1.
They can only do this once a day, so at most the number will be +1 from what it was before. But the user can click it and unlick it as many times as they want, it will only still be adding max +1 to the number.
I currently have something implemented: In my database I have a object for updatedTime. I then use a function to check if its on the same day:
private boolean isSameDay(int position){
Date currentDate = new Date();
Date updatedDate = mDataSource.get(position).getUpdated();
// Strip out the time part of each date.
int MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
long julianDayNumber1 = currentDate.getTime() / MILLIS_PER_DAY;
long julianDayNumber2 = updatedDate.getTime() / MILLIS_PER_DAY;
// If they now are equal then it is the same day.
return julianDayNumber1 == julianDayNumber2;
}
Which checks if it's the same day so user can't click on it again. Now I am stumped on figuring out how to make it toggleable so the user can click it again but it will just decrement it, and then user can click it again and it will increment it and so on, until the next day.
This is my OnClickListener for the button, not sure how to implement the toggle function.
habitChecked.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.i("In on Click:", ""+position+"");
updateHabit(position);
}
});
And this is my updateHabit method:
private void updateHabit(int position){
Realm.init(mContext);
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
if(!isSameDay(position)){ //If the habit hasn't already been updated today
mDataSource.get(position).setTracker(mDataSource.get(position).getTracker()+1);
mDataSource.get(position).setUpdated(new Date()); //update updated date
}
realm.commitTransaction();
}
To summarize: The current functionality is that the user can only click the button once a day which adds the +1, but can't "unclick" it to undo the click and increment, and then reclick it if they want to.
Any help would be appreciated and I can supply any other code that might be relevant.
Related
I'm using a time picker spinner. I would like to implement 30 min intervals.
The code I'm using outputs this effect as shown in the below image.
Here's the code:
picker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
#Override
public void onTimeChanged(TimePicker view, int hour, int min) {
timeoutput.setText(String.format("%02dh%02d", hour, min));
}
});
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Schedule.this, choosewalk.class);
startActivity(intent);
}
});
#SuppressLint("DefaultLocale")
private void TimeInterval(TimePicker picker) {
try {
int Interval = 30;
NumberPicker minute = (NumberPicker) picker.findViewById(Resources.getSystem().getIdentifier(
"minute", "id", "android"));
minute.setMinValue(0);
minute.setMaxValue((60 / Interval) - 1);
List<String> displayedValue = new ArrayList<String>();
for (int i = 0; i < 60; i += Interval) {
displayedValue.add(String.format("%02d", i));
}
minute.setDisplayedValues(displayedValue.toArray(new String[0]));
} catch (Exception e) {
e.printStackTrace();
}
}
I know that that there are similar questions, but for this specific problem, I'm struggling. I know the method works for intervals of 5, 10, 15, etc. It's altering the code for 30 min intervals that's problematic.
Ok, here's your problem. You want a wheel with 00 and 30 on it, and you want to be able to infinitely scroll it, so it ticks over from 30 to 00 and increments the hour wheel each time, right? Which is basically how the TimePicker works by default.
The issue is this, from NumberPicker:
Note: If the number of items, i.e. the range ( getMaxValue() - getMinValue()) is less than the number of items shown on the selector wheel, the selector wheel will not wrap.
the max - min thing is an extremely awkward way of expressing this (the number of items is actually that + 1) - but basically the spinner shows three items on-screen at a time, and you need to have more than three items (so at least one is off-screen) for wrapping to work. That's why is works for your other intervals (15 mins gives you four items, so that wraps)
Unfortunately I don't think there's a lot you can do about it - the lack of wrapping is hardcoded behaviour in NumberPicker. You could fake it by having four items, 00, 30, 00, 30 but internally that's still values 0 to 3, one rotation of the wheel, not two. And the TimePicker uses those values, comparing to minValue and maxValue to check when the wheel has wrapped and the hour needs to automatically change.
The listener that handles this (in TimePickerSpinnerDelegate) can't be read, so you can't wrap it in a listener that pretends it's going 0 1 0 1 instead. The listener also refers to a bunch of internal private variables and methods, so you can't just copy it into your own code and make the tweaks. You'd have to reimplement the whole widget and its related classes by the looks of things
If it works for you, you could just throw two NumberPickers together and remake it yourself. You'll lose things like the AM/PM functionality, probably accessibility, it depends if you care or not. This basically works:
public class MainActivity extends AppCompatActivity implements NumberPicker.OnValueChangeListener {
private NumberPicker mMinuteSpinner;
private NumberPicker mHourSpinner;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMinuteSpinner = findViewById(R.id.minPicker);
mHourSpinner = findViewById(R.id.hourPicker);
mMinuteSpinner.setMinValue(0);
mMinuteSpinner.setMaxValue(3);
mMinuteSpinner.setDisplayedValues(new String[]{"00", "30", "00", "30"});
mMinuteSpinner.setOnValueChangedListener(this);
mHourSpinner.setMinValue(0);
mHourSpinner.setMaxValue(23);
String[] hours = new String[24];
for (int i = 0; i < 24; i++) {
hours[i] = Integer.toString(i + 1);
}
mHourSpinner.setDisplayedValues(hours);
}
#Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
boolean advanced = (newVal == 0 && oldVal == 3) || (newVal == 2 && oldVal == 1);
boolean regressed = (newVal == 3 && oldVal == 0) || (newVal == 1 && oldVal == 2);
if (advanced) {
mHourSpinner.setValue(mHourSpinner.getValue() + 1);
} else if (regressed) {
mHourSpinner.setValue(mHourSpinner.getValue() - 1);
}
}
}
Haven't touched Java in a while! There might be a better way to do that. But yeah, the listener is just checking to see if it's passing between the two rollover points on the four-item list (where it goes from 30 to 00 scrolling one way, or vice versa scrolling the other way). This is basically how the TimePicker works
First of all i would like to introduce you with my application, so you have a better point of view what i need. I have database with three tables days, weeks, weekdays and in one Activity i'm fetching all items from days table by selected week, but i don't know how to set text to all members of that class Day. I will show you in following example what i want.
I have achieved setting text to multiple EditTexts, but with many repetition. I want to do this with arrays and loop. I have succeed initializing all EditTexts using array and loop, but i don't know how to implement setting text for all EditTexts.
This is repetition part:
for (int i = 0; i < days.size(); i++) {
// Monday
Day day1 = days.get(0);
etNasteMonday.setText(String.valueOf(day1.getNaste()));
etInsulinMondayBeforeBreak.setText(String.valueOf(day1.getInsulinBeforeBreak()));
etDiabetesMondayAfterBreak.setText(String.valueOf(day1.getDiabetesAfterBreak()));
etDiabetesMondayBeforeLaunch.setText(String.valueOf(day1.getDiabetesBeforeLaunch()));
etInsulinMondayBeforeLaunch.setText(String.valueOf(day1.getInsulinBeforeLaunch()));
etDiabetesMondayAfterLaunch.setText(String.valueOf(day1.getDiabetesAfterLaunch()));
etDiabetesMondayBeforeDinner.setText(String.valueOf(day1.getDiabetesBeforeDinner()));
etInsulinMondayBeforeDinner.setText(String.valueOf(day1.getInsulinBeforeDinner()));
etDiabetesMondayAfterDinner.setText(String.valueOf(day1.getDiabetesAfterDinner()));
etDiabetesMondayBeforeSleep.setText(String.valueOf(day1.getDiabetesBeforeSleep()));
etInsulinMondayAfterSleep.setText(String.valueOf(day1.getInsulinBeforeSleep()));
// Tuesday
Day day2 = days.get(1);
etNasteUtorak.setText(String.valueOf(day2.getNaste()));
etInsulinUtorakPreDorucka.setText(String.valueOf(day2.getInsulinBeforeBreak()));
etDiabetesUtorakPosleDorucka.setText(String.valueOf(day2.getDiabetesAfterBreak()));
etDiabetesUtorakPreRucka.setText(String.valueOf(day2.getDiabetesBeforeLaunch()));
etInsulinUtorakPreRucka.setText(String.valueOf(day2.getInsulinBeforeLaunch()));
etDiabetesUtorakPosleRucka.setText(String.valueOf(day2.getDiabetesAfterLaunch()));
etDiabetesUtorakPreVecere.setText(String.valueOf(day2.getDiabetesBeforeDinner()));
etInsulinUtorakPreVecere.setText(String.valueOf(day2.getInsulinBeforeDinner()));
etDiabetesUtorakPosleVecere.setText(String.valueOf(day2.getDiabetesAfterDinner()));
etDiabetesUtorakPredSpavanje.setText(String.valueOf(day2.getDiabetesBeforeSleep()));
etInsulinUtorakPredSpavanje.setText(String.valueOf(day2.getInsulinBeforeSleep()));
}
What should i do to make this more efficient and easier for program to read and how to implement within this code:
List<String> values = new ArrayList<>();
int[] ids = new int[]{R.id.et_naste_monday, R.id.et_insulin_monday_before_breakf, R.id.et_posle_dorucka_monday, R.id.et_pre_rucka_moday,
R.id.et_insulin_monday_pre_rucka, R.id.et_posle_rucka_monday, R.id.et_pre_vecere_moday, R.id.et_insulin_monday_pre_vecere, R.id.et_posle_vecere_monday,
R.id.et_pred_spavanje_moday, R.id.et_insulin_monday_pred_spavanje};
List<Day> days = mDatabase.getAllDaysByWeek(week.getTitle());
for (int id : ids) {
EditText t = (EditText) findViewById(id);
values.add(t.getText().toString());
t.addTextChangedListener(this);
applyChangedEditTextColor(false, values, t);
for (Day day : days) {
// Here i should do the same part as i done it in above example
}
}
Create a custom view with all these edittexts, and set a method populate(Day day) in which you will fill all those setTexts. Then you can do
mondayView.populate(day.get(0));
tuesdayView.populate(day.get(1));
More info about custom views:
https://developer.android.com/training/custom-views/index.html
https://www.toptal.com/android/android-customization-how-to-build-a-ui-component-that-does-what-you-want
I am creating an app where people report whether or not they have the flu that week. I already have the code that allows me to be able to add to the number of people who do have the flu and the number of people who don't have the flu by pressing buttons. It then creates a percentage of people who have the flu based on that data. But whenever I close out of the app, all of the data goes away. The same data also won't be able to be accessed by the other people with the app.
Here is the code for the app.
public void fluButton()
{
Button hasFluButton = (Button)findViewById(R.id.fluButton);
hasFluButton.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
TextView t1 = (TextView)findViewById(R.id.influenzaPercent);
NumberFormat defaultFormat = NumberFormat.getPercentInstance();
defaultFormat.setMinimumFractionDigits(2);
numPeopleWFlu += 1;
percentFlu = ((double)numPeopleWFlu) / (numPeopleWOFlu + numPeopleWFlu);
String percent = defaultFormat.format(percentFlu);
t1.setText(percent + " of people have had the flu this week.");
}
}
);
}
public void noFluButton()
{
Button hasNoFluButton = (Button)findViewById(R.id.noFluButton);
hasNoFluButton.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
TextView t1 = (TextView)findViewById(R.id.influenzaPercent);
NumberFormat defaultFormat = NumberFormat.getPercentInstance();
defaultFormat.setMinimumFractionDigits(2);
numPeopleWOFlu += 1;
percentFlu = ((double)numPeopleWFlu) / (numPeopleWOFlu + numPeopleWFlu);
String percent = defaultFormat.format(percentFlu);
t1.setText(percent + " of people have had the flu in missouri this year.");
}
}
);
}`.
This answer will only provide you with a very vague solution as your question is broad.
Here's what you need to do, you need to rent a server and put all the data to that server.
Why do you need a server? Because you want lots of people to access the data as the same time. If you save the data to your app's SharedPreferences or something local, other people won't be able to get it.
So now you have a server, in your app, you retrieve the data from the server at the start of your app. There are lots of external libraries out there that can help you fetch something from the internet.
After you retrieved the data, you display it in some views and BOOM! You did the first part. The second part is to save the data to the server. When the user taps on a button or something, you save the data.
Sounds easy, huh?
When trying to build an application which contains an updateable LineChart or AreaChart I recognized strange behaviour - probably due to an error in application logic?
The goal is to fill data into or update a chart when a button "Generate" is clicked. User has to input a start time and an end time for the graph, in addition an interval Hours / Days / Weeks has to be chosen (by using a RadioGroup).
Creation of the initial chart works without any problems. Re-generating the chart works properly too, but only as long as data points didn't exist in previous chart. If data points with same x-values are contained in both charts (old and updated one), sorting isn't ascending anymore.
Example:
Execution with
StartDate: 01.09.2013
EndDate: 25.09.2013
Interval: Weeks
Values on x-axis:
01.09.2013 / 08.09.2013 / 15.09.2013 / 22.09.2013
Clicking the "Days" RadioButton an re-generating the chart yields to following values on x-axis:
01.09.2013 / 08.09.2013 / 15.09.2013 / 22.09.2013 / 02.09.2013 / 03.09.2013 / 04.09.2013 / ...
(values should be 01.09.2013 / 02.09.2013 / 03.09.2013 / ...)
All values which already have been shown in first chart and are in second chart too, are sorted at the beginning of the new chart (and not in ascending order)
Here's the code that does the trick (code for method initializeTimeline is just for testing purposes (surely a bit optimizable ;))):
public class ChartDesignController implements Initializable {
#FXML
private AreaChart chartOne;
#FXML
private TextField startDate;
#FXML
private TextField endDate;
#FXML
private RadioButton radioHours;
#FXML
private RadioButton radioDays;
#FXML
private RadioButton radioWeeks;
#FXML
private ToggleGroup timeUnit;
#FXML
private Label msgBox;
#FXML
private void generateGraph(ActionEvent event) {
String timeUnit = getTimeUnit();
Series s = initializeTimeline(startDate.getText(), endDate.getText(), timeUnit);
chartOne.getData().setAll(s);
}
private String getTimeUnit() {
String timeUnitForQuery = "DD";
RadioButton selectedRadio = (RadioButton) timeUnit.getSelectedToggle();
if (selectedRadio == radioHours) {
//System.out.println("RadioHours was selected");
timeUnitForQuery = "HH24";
}
if (selectedRadio == radioDays) {
//System.out.println("RadioDays was selected");
timeUnitForQuery = "DD";
}
if (selectedRadio == radioWeeks) {
//System.out.println("RadioWeeks was selected");
timeUnitForQuery = "IW";
}
//System.out.println("Time unit changed");
return timeUnitForQuery;
}
#Override
public void initialize(URL url, ResourceBundle rb) {
}
private Series initializeTimeline(String startTime, String endTime, String timeUnit) {
msgBox.setText("");
long delta;
int nrOfTicks = 0;
Data<String, Integer> dp;
Series s = new Series();
ArrayList<Data<String, Integer>> dataPoints = new ArrayList();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Date startDate = new Date();
Date endDate = new Date();
GregorianCalendar startTimeGC = new GregorianCalendar();
GregorianCalendar endTimeGC = new GregorianCalendar();
if (timeUnit.equalsIgnoreCase("HH24")) {
sdf = new SimpleDateFormat("dd.MM.yyyy HH");
}
try {
startDate = sdf.parse(startTime);
endDate = sdf.parse(endTime);
} catch (ParseException ex) {
msgBox.setText(ex.getMessage() + "\n" + "Format expected: " + sdf.toPattern());
}
startTimeGC.setTimeInMillis(startDate.getTime());
endTimeGC.setTimeInMillis(endDate.getTime());
delta = endTimeGC.getTimeInMillis() - startTimeGC.getTimeInMillis();
if (timeUnit.equalsIgnoreCase("HH24")) {
nrOfTicks = (int) (delta / 1000 / 60 / 60) + 1;
} else if (timeUnit.equalsIgnoreCase("DD")) {
nrOfTicks = (int) (delta / 1000 / 60 / 60 / 24) + 1;
} else if (timeUnit.equalsIgnoreCase("IW")) {
nrOfTicks = (int) (delta / 1000 / 60 / 60 / 24 / 7) + 1;
}
for (int i = 0; i < nrOfTicks; i++) {
dp = new Data(sdf.format(startTimeGC.getTime()), 0);
dataPoints.add(dp);
if (timeUnit.equalsIgnoreCase("HH24")) {
startTimeGC.add(GregorianCalendar.HOUR_OF_DAY, 1);
} else if (timeUnit.equalsIgnoreCase("DD")) {
startTimeGC.add(GregorianCalendar.DAY_OF_MONTH, 1);
} else if (timeUnit.equalsIgnoreCase("IW")) {
startTimeGC.add(GregorianCalendar.WEEK_OF_YEAR, 1);;
}
}
dataPoints.sort(new DataComparator());
s.setData(FXCollections.observableList(dataPoints));
return s;
}
}
Below, the DataComparator which is in charge of sorting the dataPoints alphabetically according to their x-values:
public class DataComparator implements Comparator<Data> {
#Override
public int compare(Data d1, Data d2) {
String d1Xval = (String) d1.getXValue();
String d2Xval = (String) d2.getXValue();
return d1Xval.compareTo(d2Xval);
}
}
When debugging the program values are sorted correctly in ArrayList dataPoints.
Any ideas why values are sorted incorrectly then in chart x-axis, in case they already appeared in old chart?
Would greatly appreciate help for this "issue".
I had the same problem. No matter how I setup the plot the ordering would always get messed up by reploting with new datapoints. The only fix was using java 1.8.
This was with the latest fx at the time, 2.2.51-b13. had to go with fx8 early access release.
I just wanted to say, I got the (nearly) same issue with a line Chart!
I load some data from a database to be displayed in a line chart.
The data simply represents a sum for a month.
When I load the data for "user1" everything looks fine:
But when I load the data with my 2nd user, it looks like this:
I really can't figure out why this is happening, because i sort the data while selecting from database like this:
...NTING.CUSTOMER = '"+Customer+"' GROUP BY MONTH ORDER BY MONTH ASC;
So… that's all I can say… I order the data while fetching it from database, for one user it works, for the other one it doesn't! and it really freaks me out!
I just found a posting anywhere where someone recommends to download the 'Early Access Version' of JRE and JDK 8 - But in my opinion, I wouldn't recommend that for a productive system!
Hope anyone got the solution for that nasty problem!
Just before anyone rages about that this isn't the answer - I know that!
But I think collecting as much information as possible also appears to be a part of the solution.
And because of the (sometimes strange privilege-preferences of stackoverflow) I can't comment till I got a higher reputation value!
I didn't want to ask a new question, while this is already discussed here!
Hope this is ok…
Greets
i have encountered a similar issue with linechart trying to add Date-Points and while debugging i figured out something:
i added a Series-Object to the ObservableList which containes 3 Date Points: 01.01.2014, 02.01.2014, 02.02.2014 and some double for the y-Axis.
(So far so good, the Line Chart is shown as it should).
after this i added a second Series-Object with the Date Points: 01.01.2014, 02.01.2014, 03.02.2014.
and again: the line chart works.
If i add the second Series-Object first, my linechart will show the X-Axis values as following:
01.01.2014
02.01.2014
03.02.2014
02.02.2014
which ruins my linechart by wrong order.
On my way trying to find a solution i figured out a 'workaround':
Adding a Series Object containing all Date-Values which are used later on other Series objects as first Series-Object in the Observable List helps.
it can be 'hidden' as "Average Value" or such but
i am not really happy with it though but it works to display the chart in the correct order at least
My first post here by the way, just tried to help at least to get a solution, since i landed here searching for the same issue.
This is a workaround, recreate the whole graph every time, it is not the cleanest way, but it works. Before you add the series to the graph, just call
graph.getData().clear() and then graph.layout();, got the answer from
Recreate bar chart without it remembering data
I had the same issue with JavaFX 11, using JDK 14. It was a LineChart with CategoryAxis as xAxis that was filled with dates in a sortable format yyyy-MM-dd HH:mm:ss, but they didn't get auto-sorted, when adding multiple Series.
I've found out that for some reason the categories are not recognized (categories was empty):
CategoryAxis xAxis = (CategoryAxis) lineChart.getXAxis();
ObservableList<String> categories = xAxis.getCategories();
I'm still not sure what's the underlying reason for it not working properly out of the box, but that's the solution I came up with:
lineChart.setData(chartSeriesList);
CategoryAxis xAxis = (CategoryAxis) lineChart.getXAxis();
ObservableList<String> categories = FXCollections.observableArrayList(allDates);
Collections.sort(categories);
xAxis.setAutoRanging(true);
xAxis.setCategories(categories);
Basically explicitly setting up the categories (list of dates in string format) on the xAxis.
I found a "temporary" solution about this.
series.getData().add(new BarChart.Data<>(rs.getString(1)+" "+i,rs.getDouble(2)));
Adding an i variable, which increases with data prevents data to be ruined.
Another solution is using JDK 8.
I am new to Android application development and am trying to find a way to proceed through a series of screens that take in user input. I'm making a small math game where the user would answer basic two integer addition problems. So far the main menu is created. It has a New Game button which launches my GameActivity and it runs just fine for one math problem. However, after the user inputs their answer to the simple math problem, I would like to be able to continue on to another math problem once the user had answered the current problem and the method would return a correct/incorrect value. Initially I thought of doing something like a basic FOR loop from within the GameActivity :
for(int i = 0; i < 10; i++){ gameMethod(); }
gameMethod() is a JAVA method that simply generates 2 random numbers, adds them to get the correct answer and then prompts the user using an EditText field to type in their guess. It displays the random numbers and answer using TextView boxes created in an XML layout file.
Each call to the gameMethod would, at least I think, just re-input the randomized numbers into the TextView fields displayed on the screen each iteration. I really don't care what the previous numbers were so I figured I would just overwrite them. I wan't able to get the code to do that though. I put in a Log.d() statement or two and found that the FOR loop was in fact running through correctly 10 times, but it was not waiting for user input before firing off its next gameMethod().
In doing some looking around, I found the startActivityForResult() and wondered if this was a more appropriate way of approaching this. So in this way, I foresee having three Activities, the Main menu which calls the GameActivity which would then iterate through, say 10 times, each iteration calling yet another activity GameScreenActivity which would actually put the numbers on the screen, read in user input and then return 1 for a correct answer and 0 for an incorrect answer. So far in reading up on StarActivityForResult() I'm getting somewhat confused by the process and wondered if this was even a plausible path to be exploring.
Again, I'm very new at this Android programming and appreciate any and all help that I can get.
Thank you.
Sorry for not including the gameMethod() initially, I've added it below.
// Create and initialize arrays of integers
int[] a = {0,1,2,3,4,5,6,7,8,9,10};
int[] b = {0,1,2,3,4,5,6,7,8,9,10};
// Creates random number generator
Random randy = new Random();
// Generates two random values to add
int r1 = randy.nextInt(10);
int r2 = randy.nextInt(10);
// Calculates correct answer
int an = a[r1] + a[r2];
// Displays 1st number
TextView number1 = (TextView) findViewById(R.id.firstNumber);
number1.setText(Integer.toString(a[r1]));
// Displays 2nd number
TextView number2 = (TextView) findViewById(R.id.secondNumber);
number2.setText(Integer.toString(b[r2]));
// Displays correct answer
TextView answer1 = (TextView) findViewById(R.id.answerNumber);
//hide answer until user puts in theirs
answer1.setVisibility(View.INVISIBLE);
answer1.setText(Integer.toString(an));
//hide the answer place holder value
TextView uAnswerDisplay = (TextView) findViewById(R.id.userAnswerNumber);
uAnswerDisplay.setVisibility(View.INVISIBLE);
//Get the EditText field that the user will input their answer to
EditText inputText = (EditText) findViewById(R.id.userInput);
//set up a listener to run once the ENTER key is hit after their answer has been entered
inputText.setOnKeyListener(new EditText.OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event){
//only go on the ENTER key when pressed DOWN
if((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)){
EditText innerInputText = (EditText) findViewById(R.id.userInput); //get the EditText box reference
TextView innerUAnswerDisplay = (TextView) findViewById(R.id.userAnswerNumber); //get the TextView box that the answer will go in
String inputString = innerInputText.getText().toString(); //capture the user's input
int uAnswer = Integer.parseInt(inputString); //parse user answer to an integer
int cAnswer = Integer.parseInt((((TextView) findViewById(R.id.answerNumber)).getText()).toString());
innerUAnswerDisplay.setText(Integer.toString(uAnswer)); //display the string after converting from integer
//change colors of text based on correctness
if (uAnswer == cAnswer){ innerUAnswerDisplay.setTextColor(Color.GREEN); } //green for correct
else { innerUAnswerDisplay.setTextColor(Color.RED); } //red for incorrect
innerUAnswerDisplay.setVisibility(View.VISIBLE); //make the user input answer visible
TextView innerAnswer1 = (TextView) findViewById(R.id.answerNumber);
innerAnswer1.setVisibility(View.VISIBLE); //hide answer until user puts in theirs
} //end of if
return false; //return false
} //end of onKey
}); //end of setOnKeyListener
Sorry for all the edits, I couldn't get the edits to include the code and post correctly so I broke it up into chunks and added a little at a time.
From what you say, I'd consider two ways of letting the user answer questions:
have an onclick listener on the input EditText that triggers a new loop;
have a dialog activity that gets started in the beginning of the loop, which prompts the user for a new answer, your game activity would receive the answer via its onActivityResult.