last day (21 days later) » 

02:53
1
A: Android notifyDataSetChanged not refreshing the items after removing

Android_K.DoeTry this one itemsPending.remove(sp.keyAt(i)); adapterPending.remove(adapterPending.getItem(sp.keyAt(i))); adapterPending.notifyDataSetChanged(); EDIT: According to my research, SparseBooleanArray.size() will sometimes only return the count of true values. Try this for(int i = lstPendingPro....

Not working, I got this error 'getItem(int) in ArrayAdapter cannot be applied to (boolean)
@KelvinJigSawing Check edited answer. Use i instead in getItem
FINALLY OH MY GOD THANKS
But apparently this only works if I remove 1 item if I remove more than 1 item i get IndexOutofBoundsException invalid index 1 size is 1 error
Check sp.keyAt(i) instead of i
Still the same , if only 1 item removed its ok, if more than 1 i get the IndexOutOfBoundsException
02:53
Please log itemsPending and sp size, and where did the error points?
Also your adapter's getCount()
Hi please check the edits of the question i have logged
Basically your itemsPending.remove(); doesnt remove an item since sp.get() returns a boolean. Try using keyAt(i) or just i
if I use both keyAt(i) , single remove and multiple remove will give me OutOfBounds Error if I use i only single remove is ok but multiple remove will give me the same error
Please edit log to itemsPending.size(); sp.size(); adapterPending.getCount() before and after deletion. Separate single and multiple, thanks
Ok I think I know why on multiple deletion it has an error. Apparently if I have multiple items, so long as I check one of them, everyone gets deleted. How can I do a log before the the deletion
02:53
Log.d("returned value:", itemsPending.size(); + " " + sp.size(); + " " + adapterPending.getCount() + " " + i); before forloop and inside forloop last part before }
Hi, please check the edits on the question
Check edited answer
its wrong: imagine you have 15 items in total and 11 items are checked: [0,1 .. 9 and 14] - with your approach you will never get the last one
Yeah it's still wrong. It's the same thing. If I have 1 item. And I check it, I get an outofbound error. But if I have 2 item and check 1 of it. I get no error but even the unchecked is removed as well. If I have 2 item and check both. it's the outofbound error as well
basically you have to start with the highest index and decrement to 0
02:53
@pskink Any idea how I can do that?
i already said: start with the lstPendingPro.getAdapter().getCount() - 1
for(int i = lstPendingPro.getAdapter().getCount() - 1; i >= 0; i--)
Ok now what I experience is very weird. So after changing to for(int i = lstPendingPro.getAdapter().getCount() - 1; i >= 0; i--) the first item on the list will prompt me the Toast.makeText(ProList.this, "Please choose a profile to be submitted.", Toast.LENGTH_LONG).show(); which is after the else statement. And this is only if I have multiple Item in the list. if its the only item in the list, and i try to remove, nothing will happen no error and not removed. If I have 3 item i select JUST ONE of any other except for the first item it will remove other unchecked except the first item
@KelvinJigSawing cannot you just debug your code step-by-step? you will save a lot of time: developer.android.com/studio/debug - of course the above code is wrong but you cannot just sit down and wait for anyone else to do your homework
Yeah I am trying as we speak. But still no results so far.
02:53
@KelvinJigSawing can you let me pull your project let me try to resolve it
@Android_K.Doe sorry I dont really like github . Its under ProList.java thats the one
@Android_K.Doe if you're done just upload to some file server site where I can download it. Meanwhile I try to resolve it as well.
Ok ill see what i can do
@Android_K.Doe Thanks. Appreciated.
@KelvinJigSawing did you know how to start a discussion. The comment had been so long but the prompt doesnt come to me. By the way i need login credential
@Android_K.Doe I am unable to chat due to my low rep. username try "[email protected]" password "90368519"
02:59
Hi, i couldnt run a test because i was missing the txt file. But before that did you remove the line from "--Pending--" once you added to "--Submit--"?
the txt file is created from the whole process
from capture until your reach the end of it which is captureprog1.java
what I want to do is to remove the pending and add submit for those I selected to submit
I get error in capture
error such as?
Let me try it in my device
alright. oh yeah I think this was build in API 20 so not sure if your device may work
03:10
im stuck with louver setting.. what im i suppose to do to add item
uhh just check the "No display" checkbox
yes ive tried it redirect me to yes/no but when i choose any it redirects me again to louver
hmmm
ok look at my codes for the pre louver if yes it should bring you to louverconfig else it should be capture
oh i got it wait
03:39
I test it. And it is working fine. The problem is your file writing
i comment it out just to test the transfer of data between list and it is working just fine. i select 1 item then it removes one item then add to submit list.
ohh
because I need the removing and adding of file writing to determine which are submitted and which are considered pending
any suggestion
ill try to fix your file writing later after eating
ok sure I will be going for lunch soon as well. thank alot !
04:19
ive got it. will be updating my answer soon
04:31
I edited my answer. it is now working fine
04:55
alright thanks i will check it out
05:06
@Android_K.Doe nothing seems to be listed on my pending hmm is it because of the String filename
dont change anything.. Just add the function i made and change your for loop.. Dont remove your pendingSubmitProfile
by the way i suggest you make functionNames more understandable like getPendingProfile()
alright sure:) let me try out and see if everything works
Oh my god its working thanks so much !! oh can I ask one more favour from you? I have one last problem that I been trying to solve for couple of days
1
Q: Java Android How To Save Multiple CheckBox To String If Checked and Store To SharedPref and Retrieve It As A String

Kelvin JigSawingSo I have 2 screen one to store the other to retrieve. What I want ultimately is storing the checked checkbox into sharedPref, retrieve it as a STRING and put it inside an ArrayList to shuffle for a random STRING that was SELECTED. So far I tried many solutions but none worked. I always get the ...

if you could take a look at this that would be great
Okay let me check it for a moment
05:16
Thanks alot ! Appreciated .
05:29
I have a question, do you base your View's check state on this prefs?
uhh I dont think so
I just want whatever is selected and he click next then it will be stored
and put in an arraylist to shuffle for one
what is the purpose of shuffling? I notice that when i choose cool then submit then go back, the check state was remove and selected mode goes empty
if you still have my project earlier, if you see the capturescreen.java theres a couple of TextView
I need the textview to onlydisplay based on what was selected throughout the screens before capture
thats why I put the in an ArrayList and shuffle so I just get any random BUT SELECTED string
Hmm is it because I did an editor.clear on the screen for shared pref thats why it clears your choice when you go back
05:50
The output was already correct right? but you want a shorter solution?
uhh no it was not
i have done the mode selection already but if you look at my fanspeed louver and swing configuration screen
theres 9 checkbox
and the current method I have in my project is wrong for those
it generates even those unselected ones too
you look at the question I send you, the UpdatedReceive.java that was how I did for the cool mode which is 2checkbox but i cannot possible do that for 9 checkbox right
Ok im getting it.. Wait
My suggestion to this is to just save the preference as string and not per checkbox. You have a view that holds the selected right? Then use it. For example when i click next you will call editor.putString("Mode", tvStatus.getText().toString());
06:07
hmm thats great but the thing is if you have open my tvStatus and see my tvStatus store multiple strings when selected e.g Auto,Low,Med-Low. If the user select these 3 checkbox, how can I retrieve it over and store in array list to shuffle for just 1 of them
And on your capture you just have to call sharedPref.getString("Mode", "None");
String mode = sharedPref.getString("Mode", "None");
mode.split(",")
List<String> myList = new ArrayList<String>(Arrays.asList(mode.split(",")));
is that fine?
seems great
I can give it a try
And since the last part of the text still has coma, you can use mode = mode.substring(0, mode.length -1) to remove the last comma
so thats after the mode.split?
or you can do before saving to prefs
06:20
ok I will try
nope because when you split cool,heat, you will have 1. cool 2. heat and 3. "" i guess
im not sure though but i suggest just remove the last comma before you save to preference
ok
mode = mode.substring(0, mode.length -1)

I get an error cannot resolve length
String mode = tvStatus.getText().toString();
editor.putString("Mode", mode.substring(0, mode.length -1));
length()
alright let me try
still the same the length is red
you put the length() before commit or after
but if i do this no error
tv.length()-1));
No, do this
String mode = tvStatus.getText().toString();
editor.putString("Mode", mode.substring(0, mode.length() -1));
I still dont get why you shuffle though
well I only need one value to be displayed
its same for my temperature and the rest
hmm idk why it is not displaying anything i will let you check my codes
fanspeedconfig.java
String tv = tvStatus.getText().toString();
tveditor.putString("tv", tv.substring(0, tv.length()-1));
tveditor.commit();
SharedPreferences sharedtv = getSharedPreferences("MySharedtv", Context.MODE_PRIVATE);
String fanspd = sharedPref.getString("tv", " ");
if (fanspd !=null)
{
fanspd.split(",");
List<String> myList = new ArrayList<String>(Arrays.asList(fanspd.split(",")));
Collections.shuffle(myList);
String randMode = myList.get(0);
tvFan.setText(randMode);
}
else if(fanspd == null)
{
tvFan.setText("Not Available");
}
after the commit is the capturescreen.java
avoid using editor.clear
06:42
so i remove the editor.clear?
yeah dont clear anything.. it will just override if you put another value
okay let me give it a shot
and i suggest use apply() instead of commit() since you are not tracking the result apply() is much better for performance
alright
oh damn its working allright. But ok you know my checkboxes I have a checkbox that will disable other checkbox if they arent selected i tried to do this

else if(fanspd == null)
{
tvFan.setText("Not Available");
}

but it doesnt display Not Available it display myprevious stored in shared pref
its on your retrieve..

String fanspd = sharedPref.getString("tv", "Not Available");

if(fanspd.trimg().isEmpty())
setText("Not Available")
dont mind saving "Not Available"
06:55
ohhhhh
I always thought the second parameter is to retrieve from shardpref so it acts like a default
you can though if you really want

String mode = tvStatus.getText().toString();
editor.putString("Mode", mode.substring(0, mode.length() -1));
ok let me try
String mode = tvStatus.getText().toString();

if(mode.isEmpty()) editor.putString("Mode","Not Available");
else editor.putString("Mode", mode.substring(0, mode.length() -1));
i also notice you made a lot of SharedPreference
yeah indeed
for the if statement where do . i do the apply of the edit
You can just use same Preference but keep adding

SharedPreferences.Editor editor = getSharedPreferences("MyPref", MODE_PRIVATE).edit();
editor.putString("Sample", sample);
outside the statement

if(mode.isEmpty()) editor.putString("Mode","Not Available");
else editor.putString("Mode", mode.substring(0, mode.length() -1));

editor.apply()
07:01
oh cool ok let me try
how long you been doing android?
if your ifelse got only 1 process it is okay not to add bracket. Just for information
oh yeah I know i think its the same as C ++ programming syntax as well
after i changed to this everything becomes random again
if(tv.isEmpty()) editor.putString("Mode","Not Available");
else editor.putString("Mode", tv.substring(0, tv.length() -1));
tveditor.apply();
what do you mean? is it solved?
nono as in after i changed the putstring with the if else
it became back to my original problem
help me check what am I missing

FanSpeedConfig.java
String tv = tvStatus.getText().toString();
if(tv.isEmpty()) editor.putString("Mode","Not Available");
else editor.putString("Mode", tv.substring(0, tv.length() -1));
tveditor.apply();

CaptureScreen.java
SharedPreferences sharedtv = getSharedPreferences("MySharedtv", Context.MODE_PRIVATE);
String fanspd = sharedtv.getString("tv", " ");
if (fanspd != null)
{
fanspd.split(",");
List<String> myList = new ArrayList<String>(Arrays.asList(fanspd.split(",")));
I dont understand. I thought you want to set random text on the Capture view?
07:10
random BUT based on selected
not unselected as well
right now after I added yours if else statement even those unselected are randomized as well
impossible. unless you set all text in your tvStatus
hmm but if I remove your if else statement it would be possbible just that the not available would not be showing
push your project and let me pull it. Is it still git?
do i have to redownload it? or is there i can pull to my existing download?
07:22
yeah gotta redownload it
because the git i am using has a permission and im not the one setting it
im tracing it .. just a moment
the credentials again please i lost it
email : [email protected]
password: 90368519
set it in the editText so you wont have to input everytime you test
07:37
ohh alright
07:53
i see whats happening
you forgot you condition lol. you put if(checkBox.isChecked()) so if you choose nothing it wont run on the else
hmm
soo what should I do
update sharedPreference if you choose "Check if No FanSpd Display"
so i do another editor apply?
inside the if(checkBox.isChecked()) tveditor.putString("tv", "Not Available"); editor.apply()
ok letme try
hmm nope
it still does not display "Not Available" if i check that cb
08:01
wait
argghh not editor.apply()
tvEditor.apply()
You could have use just 1 preference to avoid confusion lol
ok wait let me try
Your code is so messy hahaha no offense
yeah I know hahahaha
you should have seen my c++ its worst
Ok so this is solve wow . You are amazing
Do you have any social media facebook or email
If I have doubts I can reach out to you?
I'm probably gonna do this for quite sometime
Try not to put all process if one statement. Create separate functions with a proper name next time
hmm
i dont have a dummy email it will expose who i am sorry.. i dunno if stackoverflow has chat aside from this
you solve the stuff I have been working on for the past few days in few hours lol
ohhh
08:15
i dont want you to know who i am jig saw
i dont wanna be in your game hahaha
well its ok hahahaha
as long as i can reach out to you when i can get help
because not everytime i can get people like you to be so responsive
oh yeah right another problem . i can do all the same for swing and louver but for swing and louver they have a pre screen and if the user choose No. How can I also display "not available" on the capture screen?
i think you can make a chat room if you visit my profile
will this chat room be removed? if not then its great
Same thing.. Update the preferense on where the NO would pass
I dont know either
08:19
Maybe not.. You can locate by visiting your question then mention me to be notified like @Kel
@KelvinJigSawing
wait let me see
oh yeah i can acess here on the first question
awesome
Alright thanks alot for your help :) I'm pretty sure we will chat again :P
Sure.. Just dont make me play a game of death my lord hahaha
Hahahahaha
08:40
oh hey by the way why I realize one thing everytime I open the app and I press home button on android and i go back to the app it will logout
is there a way to make it such that it logs out only after 5 mins of inactivity
or when the app is closed

  last day (21 days later) »