Daniel Andersson

Ranch Hand
+ Follow
since Nov 18, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
30
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Andersson

So I am using two different EditText for number input from the user. I am using “requestFocus” to switch between them.

When typing in the second EditText(minutes), I don’t want “requestFocus” to switch to hours directly when “length()==00”.
I want the switch to happen only when “length()==00” AND backspace is pressed. (As shown in image 4 below)






Here’s the solution I tried that don’t seem to work.

First I created a Boolean variable and set it to false:



I got an “setOnkeylisterner” that should change the value of “backSpace” to true when it is pressed AND when the minutes text field is empty  


Then in EditText for the minutes I got an TextWatcher that “requestFocus” only when min.length = 0 AND “backspace = true”.



Also when then entering a number in the text field for hours, “backSpace” is set to false again:



Before i tried with this solution(backSpace  and a java method "onKey" to track backspace), the EditText would change focus directly to hours. Like from image 2-4.
Now it only stays in the EditText for minutes no matter how many backspaces is being pressed so the problem might be with the tracking of the backspace key or something.

Any ideas on how I can implement the behavior I am looking for?
10 hours ago

Randy Tong wrote:When this two appearing on editText? When you long pressed the editText?


When i double click/tap fast.
12 hours ago
How can I hide "this" from EditText?

I tried to use this code:

That code removed the "copy/paste" window when clicking on the EditText but still left me with this:


Any idea how i can get rid of them?
13 hours ago
I solved my own problem. I think by adding this to the manifest file:


And changed some code of the class i posted here to:
3 months ago

Tim Holloway wrote:It looks like you need to learn the precise meanings of the words that are used to describe Java code.  This took longer than it needed to because we kept asking for the name of the class that your method was in, and you were giving us everything but.

Even at the end, you said "So I guess it wanted a class defined as "context" to get it to work?". No, it wanted an object of class Context to work. "context" is not a class.


Only in post did i miss that he asked for the class mr grumpy. But yes i have no idea what context means in java so that's why i asked, iI do need to to do some reading
3 months ago
Hi guys  i trying to write some code that would launch an activity when the phone is locked or in "rest-mode".
I don't get  it to work. Here's the code for the class i wrote:


I also added this to the layout .xml file:



To open the activity in MainActivity i got this method:

3 months ago

Ron McLeod wrote:Assuming that CountDownTimer is an anonymous class inside MainActivity, MainActivity.this would provide a reference to the application's context


Thank you sir, that code did actually work.
So I guess it wanted a class defined as "context" to get it to work?
3 months ago

Ron McLeod wrote:

Ron McLeod wrote:... post the code for the class that you are calling it from.


3 months ago

Ron McLeod wrote:

Daniel Andersson wrote:Thanks but that did not work. I want to check if the phone is locked within a startTimer class


I understood you were calling this code from the MainActivity class.  If that is not the case, then post the code for the class that you are calling it from.


Now it tells me:   """isDeviceLocked(Context) in MainActivity cannot be applied to (void)"  :/
3 months ago

Ron McLeod wrote:

Daniel Andersson wrote:What should i write within the () ?


MainActivity extends Activity which eventually extends Context so you should be able to use this
== true is not needed


Thanks but that did not work. I want to check if the phone is locked within a startTimer class so my IDE now tells me this:
""isDeviceLocked(Context) in MainActivity cannot be applied to (anonymous android.os.CountDownTimer)"
3 months ago
When only coding

my IDE tells me "isDeviceLocked(Context) in MainActivity cannot be applied to ()"
3 months ago

Ron McLeod wrote:

Daniel Andersson wrote:... I tried  this without success


Can you provide details on the what was unsuccessful?

Did you include a reference to the context?


I don't understand the context part, this boolean method is declared in the MainActivity.java file.

What should i write within the () ?
3 months ago
So i got this boolean method from the internet that should return true if the phone is locked.
But how can i check with  an if  statement if this is true or not?
I tried  this without success    


3 months ago

spencer audrey wrote:Calling methods from another class is confusing to me.


Since this was an android example i solved it with something called "intent". Might not be useful for you.
Yes agree it's confusing . :/
3 months ago

Winston Gutkowski wrote:

Daniel Andersson wrote:Okay any idea how that would look? :P

private MainActivity activity = new MainActivity( ... );

then do the call as I suggested above.

Winston


Do you mean?

MainActivity activity = new MainActivity();
               activity.updateCountDownText();

App crashes when I code it like this. Seems weird to me also to create a whole new instance of MainActivity() when I just want to call a method within it.
Oh well I might have to read more about this topic Thanks for the suggestions (y)
3 months ago