UPDATE SOLVED :
i don't know what happened, my Array is work normally when i add this code :
EditText editText= new EditText(this);
editText.setId(456 + i);
mSurveyView.addView(editText);
I don't know how to title this question. Because i am confused, but i will explain my problem with code
So, I have ArrayList data, ex : 1 2 3 4 5 , but when i try to show/debug just get 3 data like 1 3 5. I think, the ArrayList skip my data?
This is my code :
if (dataSurvey.listFieldSurvey.size() > 0) {
for (int i = 0; i < dataSurvey.listFieldSurvey.size(); i++) {
FieldSurvey xx = dataSurvey.listFieldSurvey.get(i);
String type = xx.metaSurvey.name;
Log.d("Tag", "type text " + dataSurvey.listFieldSurvey.size());
labelCaption = new TextView(getActivity());
labelCaption.setId(456 + i);
labelCaption.setText(xx.name + ". " + xx.caption);
labelCaption.setTypeface(Typeface.DEFAULT_BOLD);
mSurveyView.addView(labelCaption);
}
}
I tried Log.d "Tag", i have data size 5, but just show 3 data when i tried to show
Related
i am having two different arraylist of diffrent size,my problem is that i have to retrieve values from both the list and show that on to a textview,when i am using two loops it is first completing the inner loop and than executing outer loop and the vales are getting printed two times and if using break to break the inner loop it is completely ignoring inner loop after 1st loop.
ArrayList<LocationDto>location = new ArrayList<>();
education<EducationDto> = new ArrayList<>();
if (education.size() != 0) {
for (int j = 0; j < education.size(); j++) {
for (int k = 0; k < location.size(); k++) {
if (!education.get(j).getSpecializationTitle().equalsIgnoreCase("") && !location.get(k).getLocationName().equalsIgnoreCase("")) {
tvEducation.append(education.get(j).getEducationTitle() + "(" + education.get(j).getSpecializationTitle() + ")" + " Located at " + location.get(k).getLocationName());
} else if (education.get(j).getSpecializationTitle().equalsIgnoreCase("") && !location.get(k).getLocationName().equalsIgnoreCase("")) {
tvEducation.append(education.get(j).getEducationTitle() + " Located at " + location.get(j).getLocationName());
} else if (!education.get(j).getSpecializationTitle().equalsIgnoreCase("") && location.get(k).getLocationName().equalsIgnoreCase("")) {
tvEducation.append(education.get(j).getEducationTitle() + "(" + education.get(j).getSpecializationTitle() + ")");
} else {
tvEducation.append(education.get(j).getEducationTitle());
}
if (j != education.size() - 1) {
tvEducation.append(" , ");
}
break;
}
}
} else {
tvEducation.setText("Not Specified");
tvEducation.setTextColor(getResources().getColor(R.color.color_three));
}
what should i do now?
The break statement terminates a loop regardless of whether it has completed or not, so your problem is that you've put a break directly inside your inner for loop without some sort of condition. Therefore the first time the loop runs it will reach the break which is why it's terminating on the first iteration!
You probably mean to put the break inside the last if statement?
I have 4 textviews which take their values from dropdown list (spinner) selected at previous screen.
There can be either 2 or 4 numbers/letters as result of this selection.
The first position will always be a number and the second position will always be a letter. The third position can be a number or blank and the fourth position can be a letter or blank.
If position 3 and position 4 are blank then I need to make them equal to positions 1 & 2 respectively.
String myGrade = intent.getStringExtra("parameter_name_grade");
// above takes value of 'myGrade' from spinner selection at previous screen
String mDisplayGradeNumberEff = (" " + myGrade.charAt(0));
TextView displayGradeNumberEff = (TextView) findViewById(R.id.gradeNumberEffTV);
displayGradeNumberEff.setText(mDisplayGradeNumberEff);
String mDisplayGradeLetterEff = (" " + myGrade.charAt(1));
TextView displayGradeLetterEff = (TextView) findViewById(R.id.gradeLetterEffTV);
displayGradeLetterEff.setText(mDisplayGradeLetterEff);
// above works correctly
// from here down only works when a character is present in both positions
// if positions 3(2) and 4(3) are empty app stops running.
String mDisplayGradeNumberDia = (" " + myGrade.charAt(2));
if (mDisplayGradeNumberDia.isEmpty()) {
mDisplayGradeNumberDia = mDisplayGradeNumberEff;
}
TextView displayGradeNumberDia = (TextView) findViewById(R.id.gradeNumberDiaTV);
displayGradeNumberDia.setText(mDisplayGradeNumberDia);
String mDisplayGradeLetterDia = (" " + myGrade.charAt(3));
if (mDisplayGradeLetterDia.isEmpty()) {
mDisplayGradeLetterDia = mDisplayGradeLetterEff;
}
TextView displayGradeLetterDia = (TextView) findViewById(R.id.gradeLetterDiaTV);
displayGradeLetterDia.setText(mDisplayGradeLetterDia);
}
I Guess you have a array out of bounds exception, please provide Logcat....
Check if "myGrade" has 3/4 Characters, if it does not you can't read them with charAt(3)...
You can check the length of the String with "myGrade.length()"
When I asked this question I was fairly new to the site and didn't understand that I should post back the solution for future reference. Solution below worked so thanks to rocket for your help and sorry for the delay!
int myGradeLength = mGrade.length();
if (myGradeLength != 4) {
mDisplayGradeNumberEff = ("" + mGrade.charAt(0));
mDisplayGradeLetterEff = ("" + mGrade.charAt(1));
mDisplayGradeNumberDia = ("" + mGrade.charAt(0));
mDisplayGradeLetterDia = ("" + mGrade.charAt(1));
} else {
mDisplayGradeNumberEff = ("" + mGrade.charAt(0));
mDisplayGradeLetterEff = ("" + mGrade.charAt(1));
mDisplayGradeNumberDia = ("" + mGrade.charAt(2));
mDisplayGradeLetterDia = ("" + mGrade.charAt(3));
}
hi i have problem in displaying a value into my TextView..
For example i will input 1,2,3,4 then i like to display the output in this manner in my TextView..How can i do that? please help me, thank you in advance
1 appeared 1 times
2 appeared 1 times
3 appeared 1 times
4 appeared 1 times
here's my code:
String []values = ( sum.getText().toString().split(","));
double[] convertedValues = new double[values.length];
Arrays.sort(convertedValues);
int i=0;
int c=0;
while(i<values.length-1){
while(values[i]==values[i+1]){
c++;
i++;
}
table.setText(values[i] + " appeared " + c + " times");
c=1;
i++;
if(i==values.length-1)
table.setText(values[i] + " appeared " + c + " times");
Make your textView to support multipleLines and after that create in code a StringBuffer and append to it the results, something like
resultString.append(result).append(" appeared").append(c).append(" times\n");
after that you set text for textView like:
textView.setText(resultString.toString());
Here is the idea :
// this is test string, you can read it from your textView
String []values = ( "2, 1, 3, 5, 1, 2".toString().split(","));
int [] intValues = new int[values.length];
// convert string values to int
for (int i = 0; i < values.length; ++i) {
intValues[i] = Integer.parseInt(values[i].trim());
}
// sort integer array
Arrays.sort(intValues);
StringBuilder output = new StringBuilder();
// iterate and count occurrences
int count = 1;
// you don't need internal loop, one loop is enough
for (int i = 0; i < intValues.length; ++i) {
if (i == intValues.length - 1 || intValues[i] != intValues[i + 1]) {
// we found end of "equal" sequence
output.append(intValues[i] + " appeared " + count + " times\n");
count = 1; // reset count
} else {
count++; // continue till we count all equal values
}
}
System.out.println(output.toString()); // prints what you extected
table.setText(output.toString()); // display output
I'm developing an Android app and I have a little question. Let me explain the goal first:
The goal is that the user has multiple items: eg. Item 1, Item 2 and Item 3.
Every item has subitems: eg. Subitem 1, Subitem 2, Subitem 3.
So for example the user selects: Subitem 2 within Item 3.
Now the question is: Can i go back and forward in items without clicking them?
I all ready have an option to read the numbers from the string and edit them.
But what I want is that the subitem can't go further then 1~3, and if the item is 1 and the subitem is 3 and the next btn is pressed that it changes the selection to item 2 and subitem 1.
If i make my self clear enough, if i do there must be a vice versa option!!!
So if the item is 2 and the subitem is 1 and the back btn is pressed the item is 1 and the subitem is 3.
2 Little notes, but very important:
Now the item's can't go higher then 1~10
And the subitem's can't go higher then 1~3.
Here is the code I have so far:
int weeknr;
int trainingnr;
weeknr = Integer.valueOf(String.valueOf(
week.replaceAll("[a-zA-Z]", "")).replace(" ", ""));
trainingnr = Integer.valueOf(String.valueOf(
training.replaceAll("[a-zA-Z]", "")).replace(" ",
""));
if (weeknr > 0 && trainingnr > 0) {
week = "Week " + String.valueOf(weeknr - 1);
if (trainingnr != 1 && weeknr >1) {
trainingnr = 3;
weeknr = weeknr - 1;
}
training = "Training " + String.valueOf(trainingnr - 1);
trainingSelected = "";
trainingSelected = week + "_" + training;
playTraining();
If you are dutch or a friend of yours is (because the app and every thing releated to the app is dutch too) AND you have the best/working answer, you can get a Premium code for this app!
Essentially, you are defining a tree structure, and want to traverse it inorder. This is easiest if the child nodes have a reference to their parent node.
Each node should have an interface to get the next child and get the parent. Once the nodes are implemented you can build your iterator to use them.
I fixed it by doing this:
int weeknr;
int trainingnr;
weeknr = Integer.valueOf(String.valueOf(
week.replaceAll("[a-zA-Z]", "")).replace(" ", ""));
trainingnr = Integer.valueOf(String.valueOf(
training.replaceAll("[a-zA-Z]", "")).replace(" ",
""));
if (weeknr == 10) {
Log.d("TrainingControl", "Week is equal to 10");
if (trainingnr == 3) {
Log.d("TrainingControl", "Training is equal to 3");
Toast.makeText(
MainActivity.this,
"Dit is de laatste training, u kunt niet verder naar de volgende",
Toast.LENGTH_SHORT).show();
}else if(trainingnr < 3){
Log.d("TrainingControl", "Training is less then 3");
training = "Training " + String.valueOf(trainingnr + 1);
}
} else if(weeknr < 10){
Log.d("TrainingControl", "Week is less then 10");
//Week +1 if training equals 3 and the week is less then 10
if (trainingnr == 3) {
Log.d("TrainingControl", "Training is equal to 3");
week = "Week " + String.valueOf(weeknr + 1);
training = "Training " +1;
}else if(trainingnr < 3){
Log.d("TrainingControl", "Training is less then 3");
//Training +1 if training is less then 3 and the week is less then 10
training = "Training " + String.valueOf(trainingnr + 1);
}
}
trainingSelected = "";
trainingSelected = week + "_" + training;
playTraining();
I made the mistake by thinking that != means equal to, but it means NOT equal to, so by replacing the != in the previous post, and editing the code a bit so there can't be negative values any more, THIS WORKS LIKE CHARM NOW!!
Good luck for everybody who needs this!
ok so i create an array that has integers. The array displays five number from the min and max. How can i display all five numbers in a textview or edittext ? I tried:
nameofile.setText(al.get(x).toString());
but it only displays one?
ArrayList<Integer> al = new ArrayList<Integer>();
for (int i = minint; i <= maxint; i++)
al.add(i);
Random ran = new Random();
for (int i = 0; i < 5; i++) {
int x = al.remove(ran.nextInt(al.size()));
String myString = TextUtils.join(", ", al);
lottonumbers.setText(myString);
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(0);
al.add(1);
al.add(5);
al.add(4);
al.add(3);
java.util.Collections.sort(al);//for sorting Integer values
String listString = "";
for (int s : al)
{
listString += s + " ";
}
nameofile.setText(listString);
You're currently only printing out one element (the one at index x). If you want to print them all in order, you can just join them using TextUtils.join().
Update: After seeing your edit, I think there's a better way to go about what you're trying to do. Instead of trying to pull the values one at a time, and update the list, why not just shuffle them, then use the above method?
Update 2: Okay, I think I finally understand your problem. Just a simple change, then.
ArrayList<Integer> al = new ArrayList<Integer>();
for (int i = minint; i <= maxint; i++)
al.add(i);
Random ran = new Random();
StringBuilder text = new StringBuilder(); // Create a builder
for (int i = 0; i < 5; i++) {
int x = al.remove(ran.nextInt(al.size()));
if (i > 0)
text.append(", "); // Add a comma if we're not at the start
text.append(x);
}
lottonumbers.setText(text);
al.get(x).toString() will only get the value at index "x". If you want to display all values, you need to combine all of the values from the array into a single string then use setText on that string.
You are only showing one number of your array in the TextView, you must to concat the numbers to see the others results like:
for(Integer integer : al) {
nameofile.setText(nameofile.getText() + " " + al.get(x).toString());
}
Then i think you can show all number in one String.