So recently i bought Xiaomi mi a2 and tried to root it. I installed TWRP, then Magisk, everything was going well until i decided to mess with the build.prop. I changed some settings, so the phone thinks it's Samsung galaxy S9. Then notifications started not popping up and i tried to reinstall ROM. I deleted everything using TWRP (absolutely everything) and then i tried flashing stock ROM with Mi Flash toll and kept getting error: "Flash system_a error". Then i went into flash_all.bat and installed everything manually with command prompt, to both partitions. After that fastboot reboot and it now is stuck on Google one logo and does not go any further. Pc is not detecting it anymore in fastboot and I cant access recovery, it simply doesn't work. It still turns on so i hope I can recover it. Im all new to rooting so sorry if i won't understand something. I think it doesn't boot up because it thought that it's Samsung Galaxy S9 and so it didn't let me install Xiaomi ROM and so I force installed it. Hope you can help me, i am really desperate to fix it as fast as possible.
Just after posting this i found another post here with a guy having the same situation as me and i'll try to od the test pins method.(hope it works)
This is the error log:
[22:36:27]:10 COM10 6,9961779s write time out,maybe device was disconnected.
[22:37:00]:10 COM10 0,4752161s [22:37:00 COM10]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:38:21]:30 COM30 4,935272s write time out,maybe device was disconnected.
[22:39:06]:30 COM30 0,4636368s [22:39:06 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:42:01]:30 COM30 3,5075972s write time out,maybe device was disconnected.
[22:42:23]:30 COM30 0,0421577s [22:42:23 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:43:00]:30 COM30 0,3836646s [22:43:00 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort(SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
kurogam3 said:
So recently i bought Xiaomi mi a2 and tried to root it. I installed TWRP, then Magisk, everything was going well until i decided to mess with the build.prop. I changed some settings, so the phone thinks it's Samsung galaxy S9. Then notifications started not popping up and i tried to reinstall ROM. I deleted everything using TWRP (absolutely everything) and then i tried flashing stock ROM with Mi Flash toll and kept getting error: "Flash system_a error". Then i went into flash_all.bat and installed everything manually with command prompt, to both partitions. After that fastboot reboot and it now is stuck on Google one logo and does not go any further. Pc is not detecting it anymore in fastboot and I cant access recovery, it simply doesn't work. It still turns on so i hope I can recover it. Im all new to rooting so sorry if i won't understand something. I think it doesn't boot up because it thought that it's Samsung Galaxy S9 and so it didn't let me install Xiaomi ROM and so I force installed it. Hope you can help me, i am really desperate to fix it as fast as possible.
Just after posting this i found another post here with a guy having the same situation as me and i'll try to od the test pins method.(hope it works)
Click to expand...
Click to collapse
So you can't go in fastboot mode?
are you sure you flashed all partitions manually?
if so, try this command
fastboot erase ddr
Teply
Nebrassy said:
are you sure you flashed all partitions manually?
if so, try this command
fastboot erase ddr
Click to expand...
Click to collapse
Thank you for your response, Yes i flashed all partitions manually and as i said before if i go into fastboot pc doesnt see anythin. Today i managed to open up the phone and did the test points method but after trying to flash the stock rom that IS in C: partion on pc i keep getting error "requested resource is in use"
I would try the command if pc would see the phone in fastboot but it does'nt.
It only shows up with test point method as qualcom smth. Maybe i can use commands in edl mode too?
Lurensu said:
So you can't go in fastboot mode?
Click to expand...
Click to collapse
Yes i CAN'T go into fastboot.
kurogam3 said:
Thank you for your response, Yes i flashed all partitions manually and as i said before if i go into fastboot pc doesnt see anythin. Today i managed to open up the phone and did the test points method but after trying to flash the stock rom that IS in C: partion on pc i keep getting error "requested resource is in use"
I would try the command if pc would see the phone in fastboot but it does'nt.
It only shows up with test point method as qualcom smth. Maybe i can use commands in edl mode too?
Click to expand...
Click to collapse
When it shows up as qualcomm it means it's in edl mode, you need to use mi flash
Nebrassy said:
When it shows up as qualcomm it means it's in edl mode, you need to use mi flash
Click to expand...
Click to collapse
I used newest mi flash 2018 nad i got an error. I updated the first post its attached there
Error log:
[22:36:27]:10 COM10 6,9961779s write time out,maybe device was disconnected.
[22:37:00]:10 COM10 0,4752161s [22:37:00 COM10]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:38:21]:30 COM30 4,935272s write time out,maybe device was disconnected.
[22:39:06]:30 COM30 0,4636368s [22:39:06 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:42:01]:30 COM30 3,5075972s write time out,maybe device was disconnected.
[22:42:23]:30 COM30 0,0421577s [22:42:23 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:43:00]:30 COM30 0,3836646s [22:43:00 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
kurogam3 said:
I used newest mi flash 2018 nad i got an error. I updated the first post its attached there
Error log:
[22:36:27]:10 COM10 6,9961779s write time out,maybe device was disconnected.
[22:37:00]:10 COM10 0,4752161s [22:37:00 COM10]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:38:21]:30 COM30 4,935272s write time out,maybe device was disconnected.
[22:39:06]:30 COM30 0,4636368s [22:39:06 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:42:01]:30 COM30 3,5075972s write time out,maybe device was disconnected.
[22:42:23]:30 COM30 0,0421577s [22:42:23 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
[22:43:00]:30 COM30 0,3836646s [22:43:00 COM30]:System.IO.IOException: The requested resource is in use.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash() at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at XiaoMiFlash.code.bl.SerialPortDevice.registerPort( SerialPort port)
at XiaoMiFlash.code.bl.SerialPortDevice.XiaomiFlash()
Click to expand...
Click to collapse
Are you using a usb 3.0 port?
Nebrassy said:
Are you using a usb 3.0 port?
Click to expand...
Click to collapse
No
kurogam3 said:
No
Click to expand...
Click to collapse
I'm not sure but this might be a problem with the PC, did you try another one?
Nebrassy said:
I'm not sure but this might be a problem with the PC, did you try another one?
Click to expand...
Click to collapse
No, i agree that it might be a pc problem, if i can ill try with a different pc, thank you for your help, and quick responses <
P.s idk how to thank you i mean the thanks button..
kurogam3 said:
No, i agree that it might be a pc problem, if i can ill try with a different pc, thank you for your help, and quick responses <
P.s idk how to thank you i mean the thanks button..
Click to expand...
Click to collapse
Now you're problems solved or not solve
this worked for me
i think you tried playing fortnite in it btw i play fortnite on my mi a2 and it works fine but about ur iissue i had the same thing but i did some stupid **** with gl tools and i was stuck booting i just manually flashed the stock pie rom and it worked i used this:https://forum.xda-developers.com/showpost.php?p=77302899&postcount=4
hope it helps
sandrosandroN2 said:
i think you tried playing fortnite in it btw i play fortnite on my mi a2 and it works fine but about ur iissue i had the same thing but i did some stupid **** with gl tools and i was stuck booting i just manually flashed the stock pie rom and it worked i used this:https://forum.xda-developers.com/showpost.php?p=77302899&postcount=4
hope it helps
Click to expand...
Click to collapse
Yes exatcly, now i fixed it with test points or smth like that, got pie running and downloading gl tools, thanks for your reply, have a great day!
RSG14 said:
Contact MOD EDIT: Content Removed on Telegram
They'll fix your phone in no time
Click to expand...
Click to collapse
google "test point" and how to enter edl mode to flash stock ..it will work ..dont despair
Sent from my wayne using XDA Labs
Related
can some one help me find the errors on this program
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const strLowerCase As String = "visual basic"
strLowerCase = strLowerCase.ToUpper
txtOutput.Text = strLowerCase
End Sub
End Class
Try using the CODE tags around the text so it gets formatted correctly. Or paste it here and post the link http://pastebin.com/
veeman said:
Try using the CODE tags around the text so it gets formatted correctly. Or paste it here and post the link http://pastebin.com/
Click to expand...
Click to collapse
http://pastebin.com/0Qw1kKJ0#
Code:
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const strLowerCase As String = "visual basic"
strLowerCase = strLowerCase.ToUpper
txtOutput.Text = strLowerCase
End Sub
End Class
fujirio said:
http://pastebin.com/0Qw1kKJ0#
Code:
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const strLowerCase As String = "visual basic"
strLowerCase = strLowerCase.ToUpper
txtOutput.Text = strLowerCase
End Sub
End Class
Click to expand...
Click to collapse
You've declared "strLowerCase" as constant, so you can't assign a value to it, you can only read it. So, the working code should look like this:
Code:
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Dim strLowerCase1 as string
Const strLowerCase As String = "visual basic"
strLowerCase1 = strLowerCase.ToUpper
txtOutput.Text = strLowerCase1
End Sub
End Class
But also you can make it shorter like this:
Code:
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const strLowerCase As String = "visual basic"
txtOutput.Text = strLowerCase.ToUpper
End Sub
End Class
kibermaster said:
You've declared "strLowerCase" as constant, so you can't assign a value to it, you can only read it. So, the working code should look like this:
Code:
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Dim strLowerCase1 as string
Const strLowerCase As String = "visual basic"
strLowerCase1 = strLowerCase.ToUpper
txtOutput.Text = strLowerCase1
End Sub
End Class
But also you can make it shorter like this:
Code:
Public Class DemoUpper
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const strLowerCase As String = "visual basic"
txtOutput.Text = strLowerCase.ToUpper
End Sub
End Class
Click to expand...
Click to collapse
wow thank you so much
Hi all,
Some days ago I decided to make an app to help me in my job with some Maths, so I'm reading a lot and watching some classes on youtube to make it possible. I'm trying to make, basically, a calculator for some specific maths.
By a simple way, I learned how to make my EditText,TextView , and do the Math when I push one BUTTON, but in some cases, for a fast and easy result, would be better to update the "children" field, just when I edit the "parent" field, or when I leave it.
Like, if I type the number 1 in my first field, the second field that depends on it should update automatically using this reference that I just edited.
Is there possible ? If yes, recommended or it makes the app too "heavy" ? Considering that each activity would have just few maths, far from any big known app.
Thanks in advanced.
Barata
Hello,
Let's suppose you have one EditText and one TextView, with ids in your xml: myedittext1 and mytextview2. You can easily achieve that. I don't think that it will be heavy just for few maths But also if it is heavy, it can be done without making the UI thread unresponsive, using thread for the calculations.
So
Code:
final EditText et1 = (EditText) findViewById(R.id.myedittext1);
final TextView tv2 = (TextView) findViewById(R.id.mytextview2);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
//This is called AFTER the text has changed
//Now update the tv2
String textOutput = ...;
//tv2.setText(textOutput);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//This is called BEFORE the text has changed
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//This is called WHENEVER the text has changed
}
});
Button b1 = (Button) findViewById(R.id.mybutton);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//do your math calculations here (if they are heavy, start a thread here)
//Edit the et1 here
//tv2 will be edited automatically according to the afterTextChanged above
}
});
If you would like to start a thread (if your maths are heavy), to avoid UI pausing and slow response from UI, follow the below code
//Thread solution (avoid making UI "laggy")
Before onCreate inside you Activity class:
Code:
EditText et1 = null;
TextView tv2 = null;
Thread t1 = null;
MyCalc mycalc = null;
MyCalc2 mycalc2 = null;
private class MyCalc implements Runnable{
public MyCalc(){
}
@Override
public void run(){
//Do you math here
final String outputText = ...;
try{
runOnUiThread(new Runnable() {
@Override
public void run() {
//Here set et1 text
et1.setText(outputText);
//tv2 text will be updated automatically
}
});
}catch (InterruptedException e){
}
});
}
private class MyCalc2 implements Runnable{
public MyCalc2(){
}
@Override
public void run(){
//Do you math here
final String outputText = ...;
try{
runOnUiThread(new Runnable() {
@Override
public void run() {
//Here set et1 text
et1.setText(outputText);
//tv2 text will be updated automatically
}
});
}catch (InterruptedException e){
}
});
}
Inside onCreate:
Code:
et1 = (EditText) findViewById(R.id.myedittext1);
tv2 = (TextView) findViewById(R.id.mytextview2);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
//This is called AFTER the text has changed
//if you need to do calculation here also, do:
mycalc2 = new MyCalc2(); //where MyCalc2 is the same as MyCalc but with different calculations :P
t1 = new Thread(mycalc2);
t1.start();
//Set tv2 text here.
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//This is called BEFORE the text has changed
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//This is called WHENEVER the text has changed
}
});
Button b1 = (Button) findViewById(R.id.mybutton);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mycalc = new MyCalc();
t1 = new Thread(mycalc);
t1.start();
}
});
In onDestroy:
Code:
if(t1!=null){
if(t1.isAlive()==true){
if(t1.isInterrupted()==false){
t1.interrupt();
try{
t1.join();
}catch (InterruptedException e){
}
}
}
t1= null;
}
If you still need help, feel free to ask
Really thanks for the reply @MMDeveloper, but had some problems here, I'm trying to find a Solution for almost 1hr, and nothing.. I saw some ppeople with the same problem, but couldnt use the answers I've read to solve this code.
With the first solution you gave to me, I just delete the button part, just to try make all automatic. In this first sample I have just a simple math that should convert a CV power do kW
The studio shows that to me:
addTextChangedListener - Cannot resolve symbol;
TextWatcher - Invalid method declaration, return type required;
@Override - Annotations are not allowed here;
Editable arg0 - Cannot resolve symbols, for both;
I tried to put this code in different places in my main java, but nothing. Below is my XML and then my Java, could you take a look in it please ? I guess I'm used to copy and paste some codes from some classes, and that is harming me, i really need to start all over from the java sintaxe.
The fields I've changed to be those in your code are: torque_p_cv (edit) and torque_p_cv (view)
XML:
Code:
<RelativeLayout xmlns:android="CANT SHOW LINK UNDER 10 POSTS"
xmlns:tools="CANT SHOW LINK UNDER 10 POSTS"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Calculos001_Main">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cálc. do torque em função de P e n"
android:id="@+id/torque_titulo"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold|italic" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="P"
android:id="@+id/torque_tits_p" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Potência do motor"
android:id="@+id/textView"
android:layout_marginStart="10dp" />
<EditText
android:layout_width = "0dp"
android:layout_height="wrap_content"
android:id="@+id/torque_p_cv"
android:layout_weight="1"
android:inputType="number"
android:hint="Potência"
android:gravity="end"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CV"
android:id="@+id/unidade_CV"
android:textAlignment="textEnd"
android:gravity="end"
android:layout_marginStart="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="xxxxx"
android:id="@+id/torque_p_kw"
android:textAlignment="textEnd"
android:gravity="end"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="kW"
android:id="@+id/unidade_kW"
android:textAlignment="textEnd"
android:gravity="end"
android:layout_marginStart="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
and the Java:
Code:
package com.example.tbarata.calculos_001;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
public class Calculos001_Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculos001__main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_calculos001__main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
final EditText et1 = (EditText) findViewById(R.id.torque_p_cv);
final TextView tv2 = (TextView) findViewById(R.id.torque_p_kw);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
//This is called AFTER the text has changed
//Now update the tv2
String textOutput = "0";
//tv2.setText(textOutput);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//This is called BEFORE the text has changed
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//This is called WHENEVER the text has changed
}
});
}
Really thanks,
Barata
Hello again!!
I was watching some classes now on youtube, and I made some tests that almost worked for what I want.
In this code, I cant edit one EditText and show a message in the 3 situations, before, on and after change the text.... and I did changes in the TextView created with AFTER, but just changed to a simple word, a text. That worked perfectly.
Now I'm trying to make a simple math, but I'm making some mistake with numbers and texts. I just need to multiply the EditText for a number (0.7354988) and put the result in the TextView, so I would convert CV to kW, but it gives me a message that I cant do it. I create one double CVtokWfactor with that value, but I'm not sure if I did it right.
this is the error:
Error44, 49) error: bad operand types for binary operator '*'
first type: EditText
second type: double
Below the JAVA:
Code:
package com.example.tbarata.textvalidation;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class TextValidation extends Activity implements TextWatcher{
EditText ed1;
TextView tv2;
double CVtokWfactor = 0.7354988;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_validation);
ed1=(EditText) findViewById(R.id.editText1);
ed1.addTextChangedListener(this);
tv2=(TextView) findViewById(R.id.textView2);
}
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
Toast.makeText(this, "before", Toast.LENGTH_SHORT).show();
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
Toast.makeText(this, "on change", Toast.LENGTH_SHORT).show();
}
@Override
public void afterTextChanged(Editable editable) {
Toast.makeText(this, "after", Toast.LENGTH_SHORT).show();
tv2.setText(String.format("%.2f", (ed1 * CVtokWfactor)));
}
}
What should I change to multiply these numbers ?
Thanks again.
Barata
Hello
For your first reply:
You have to put the code with the EditText inside the onCreate method. You made it work in the above code that you posted (outside onCreate) because you implemented the TextWatcher interface. You could avoid that by adding the code related with TextWatcher inside the onCreate method as I posted above
For your second reply:
In the afterTextChanged method, at
Code:
tv2.setText(String.format("%.2f", (ed1 * CVtokWfactor)));
You multiply the EditText ed1 with the double CVtokWfactor. You can't multiply an EditText with a number. The operand * needs numbers (int, double, float, etc )
You need to get the text of the ed1, convert it to double (I suppose edittext has double number) and then multiply, like this:
Code:
tv2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
Also I recommend to remove the Toasts from the methods beforeTextChanged, onTextChanged and afterTextChanged. They are called each time you type something on the EditText ed1.
If you still need help, feel free to ask
Hi!
Now it worked perfectly @MMDeveloper!! really thanks !
Agree with you about the Toast code, I forgot to delete it before paste here, it was just a test to see the events
About the way of using the TextWatcher, should I use the first way that you said, for some specific reason or basically both are the same ?
And now that's working, came the idea to improve the math, for an easy way of using it.
Now I can convert power in CV to kW, but lets say that I have one value in kW already, and need to convert to CV, would be posible using this same code/activity ? So I would convert in the same activity both units. Or, its gonna be some redundant thing ? My idea to save space, is use just the 2 fields, without one third to get the result.
This is the code now, already changed for a second EditText and not TextView anymore, until now it's working to convert the unit CV to kW, just when I clean out the EditTex1 field, the EditText2 keeps the conversion from the last number in the EditText1. Actually it's not a problem for now, the important is just convert it
Code:
public class Calc001Activity extends Activity implements TextWatcher {
EditText ed1;
EditText ed2;
double CVtokWfactor = 0.7354988;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc001);
ed1=(EditText) findViewById(R.id.editText1);
ed1.addTextChangedListener(this);
ed2=(EditText) findViewById(R.id.editText2);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
try {
ed2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
}
catch (NumberFormatException e) {}
}
}
Thanks in advanced.
Barata.
Let's fix the issue with the old conversion first
When you clear the ed1 your
Code:
ed2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
}
should cause your app to crash, because Double conversion from an empty string would throw the NumberFormatException.
You are already catching it so it silently ignores it, and the ed2 is not updated.
To solve this just make a check:
Code:
@Override
public void afterTextChanged(Editable s) {
if(doNoEnterEd1==true){
return;
}
doNotEnterEd2 = true;
try {
if(ed1.getText().toString().equals("")){
ed2.setText("");
}
else{
ed2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
}
}
catch (NumberFormatException e) {}
doNotEnterEd2 = false;
}
Now it should clear the ed2 too, when you clear the ed1.
Now for the TextWatcher, you should do it as I mentioned in my first reply, only for having a separate TextWatcher for each EditText, but there is no problem with implenting the TextWatcher, as you did. Just for code clarity. Furthermore, for code clarity (and reusability), the text watcher should be in a separate Java class, but no need for such a small application So you are ok with that.
You can easily do the reverse conversion (from ed2 to ed1) as follows:
Inside your class outside any method, where you declared your EditText add:
Code:
boolean doNotEnterEd1=false;
boolean doNotEnterEd2=false;
in the onCreate method:
Code:
ed2=(EditText) findViewById(R.id.editText2);
ed2.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
if(doNoEnterEd2==true){
return;
}
doNotEnterEd1 = true;
try {
if(ed2.getText().toString().equals("")){
ed1.setText("");
}
else{
ed1.setText(String.format("%.2f", (Double.parseDouble(ed2.getText().toString()) * CVtokWfactor))); //Here do the conversion as you like, replace CVtokWfactor.
}
}
catch (NumberFormatException e) {}
doNotEnterEd1=false;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
I think it should work like intended now.
If you still encounter a problem feel free to ask
Hello!
@MMDeveloper, thanks man!!!
The code is working perfectly!! I changed the code as in the first reply and with these last modifications, its 100%!
Now I'm gonna improve the layout and add the others inputs for the math, but the base code is fully working
Really thanks for you time, helping me.
As reference, this is my code now (still without the improvement):
Code:
package com.example.barata.calc001;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Calc001Activity_002 extends Activity {
double CVtokWfactor_2 = 0.7354988;
boolean doNotEnterEd1=false;
boolean doNotEnterEd2=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc001_activity_002);
final EditText ed1_2 = (EditText) findViewById(R.id.editText02_1);
final EditText ed2_2 = (EditText) findViewById(R.id.editText02_2);
ed1_2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(doNotEnterEd1==true){
return;
}
doNotEnterEd1 = true;
try {
if(ed1_2.getText().toString().equals("")){
ed2_2.setText("");
}
else{
ed2_2.setText(String.format("%.3f", (Double.parseDouble(ed1_2.getText().toString()) * CVtokWfactor_2)));
}
}
catch (NumberFormatException e) {}
doNotEnterEd2 = false;
}
});
ed2_2.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
if(doNotEnterEd2==true){
return;
}
doNotEnterEd1 = true;
try {
if(ed2_2.getText().toString().equals("")){
ed1_2.setText("");
}
else{
ed1_2.setText(String.format("%.3f", (Double.parseDouble(ed2_2.getText().toString()) * CVtokWfactor_2))); //Here do the conversion as you like, replace CVtokWfactor.
}
}
catch (NumberFormatException e) {}
doNotEnterEd1=false;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
}
public void vemPara001(View view) {
Intent vem001 = new Intent(this, Calc001Activity.class);
startActivity(vem001);
finish();
}
public void vaiPara003(View view) {
Intent vai003 = new Intent(this, Calc001Activity_003.class);
startActivity(vai003);
finish();
}
}
Thanks again!
barata.
Hi again!!
Sorry bring this topic back, but I gave up of doind my sliding tabs to get a nice layout in this app... so I got this one with a sliding menu from left, the I thought would be nice to use.
This is the link:
https://github.com/JulienGenoud/android-percent-support-lib-sample
Actually, the focus on its sample is to use the PERCENT lib, but that I don't care, just need to use the sliding menu;
I tried to replace the view1.xml for that with the code above (with textWatcher) and created one view_1.java with the codes, but nothing happens when I type a number in the editText....
Because the app uses a Drawer or fragment, should I change the way of doing that and automatically update the fields?
Thanks again!
Barata
I've been using Android Studio for a while, and it's one of the (if not the) most powerful IDE's I've used.
There is one thing I can't find though.
If you have a list like this:
Code:
private String username = null;
private String userAvatarURL = null;
private String bio = null;
private String birhtdate = null;
private String gender = null;
private String location = null;
private String twitter = null;
private String externalURL = null;
private String urlIFLprofile = null;
private String urlIFLwallpapers = null;
private List<Integer> wallpaperIdArray = null;
How do you change private to public without changing them one by one?
Thanks for the tip!
Tim
tim687 said:
I've been using Android Studio for a while, and it's one of the (if not the) most powerful IDE's I've used.
There is one thing I can't find though.
If you have a list like this:
Code:
private String username = null;
private String userAvatarURL = null;
private String bio = null;
private String birhtdate = null;
private String gender = null;
private String location = null;
private String twitter = null;
private String externalURL = null;
private String urlIFLprofile = null;
private String urlIFLwallpapers = null;
private List<Integer> wallpaperIdArray = null;
How do you change private to public without changing them one by one?
Thanks for the tip!
Tim
Click to expand...
Click to collapse
Code:
public String username = null;
public String userAvatarURL = null;
public String bio = null;
public String birhtdate = null;
public String gender = null;
public String location = null;
public String twitter = null;
public String externalURL = null;
public String urlIFLprofile = null;
public String urlIFLwallpapers = null;
public List<Integer> wallpaperIdArray = null;
Use Edit -> Find... -> Replace
Rember shortcut "Replace" .
Bye
cristaccio85 said:
Code:
public String username = null;
public String userAvatarURL = null;
public String bio = null;
public String birhtdate = null;
public String gender = null;
public String location = null;
public String twitter = null;
public String externalURL = null;
public String urlIFLprofile = null;
public String urlIFLwallpapers = null;
public List<Integer> wallpaperIdArray = null;
Use Edit -> Find... -> Replace
Rember shortcut "Replace" .
Bye
Click to expand...
Click to collapse
I knew that one, but what if your Object names contain public or private?
such as
Code:
private boolean visibleToPublic = false;
Hello!
i need some help, i am creating a Grid View with this java code:
MainActivity
public class MainActivity extends AppCompatActivity {
private GridView gridView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView)findViewById(R.id.gridview);
gridView.setAdapter(new GridAdapter(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Click to expand...
Click to collapse
Product
public class Product {
private static String nombrePizza;
private static String ingredientesPizza;
private static int imagenPizza;
private static int idThumbnail;
public Product(String nombrePizza, String ingredientesPizza, int imagenPizza){
this.nombrePizza = nombrePizza;
this.ingredientesPizza = ingredientesPizza;
this.imagenPizza = imagenPizza;
}
public String getNombrePizza(){return nombrePizza;}
public String getIngredientesPizza(){return ingredientesPizza;}
public int getImagenPizza(){return imagenPizza;}
public int getId(){return nombrePizza.hashCode();}
public static Product[] Pizzas={
new Product(
"Proscuito",
"Jamon York y queso",
R.drawable.imagenprueba),
new Product(
"Tropical",
"Jamon York, queso y piña",
R.drawable.imagenprueba),
new Product(
"Barbacoa",
"Carne picada, queso y salsa Barbacoa",
R.drawable.imagenprueba),
new Product(
"Romana",
"Jamon York, champiñones y queso",
R.drawable.cubo),
};
public static Product getItem(int id) {
for (Product item : Pizzas) {
if (item.getId() == id) {
return item;
}
}
return null;
}
}
Click to expand...
Click to collapse
Grid Adapter
public class GridAdapter extends BaseAdapter {
private final Context mContext;
public GridAdapter(Context c){
this.mContext = c;
}
@Override
public int getCount(){return Product.Pizzas.length;}
@Override
public Product getItem(int position){return Product.Pizzas[position];}
@Override
public long getItemId(int position){return 0;}
@Override
public View getView(int position, View ConvertView, ViewGroup viewGroup){
if(ConvertView == null){
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertView = inflater.inflate(R.layout.grid_item, viewGroup, false);
}
TextView name = (TextView)ConvertView.findViewById(R.id.grid_mainText);
ImageView image = (ImageView) ConvertView.findViewById(R.id.grid_image);
TextView descripcion = (TextView) ConvertView.findViewById(R.id.grid_subText);
final Product item = getItem(position);
image.setImageResource(item.getImagenPizza());
name.setText(item.getNombrePizza());
descripcion.setText(item.getIngredientesPizza());
return ConvertView;
}
}
Click to expand...
Click to collapse
It work fine except for one thing, the app only shows the last product of the java code (Pizza romana)four times
I dont know why my app do this, can somebody help me??
Thank you! :fingers-crossed:
Hi, Can someone please help me to resolve the following issue?
I have an arraylist that I have created in an activity file. Name of this arraylist is doctorList and it is public. But when I try to populate a listview with this arraylist using setadapter, it refuses to identify the arraylist.
Code:
private ListView docList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_doctor__list);
docList = (ListView) findViewById(R.id.docList);
docList.setAdapter(new ArrayAdapter<String>(Doctor_List.this, android.R.layout.simple_list_item_1, [B][U][I]doctorList[/I][/U][/B]));
}
The doctorList appears red and it says the symbol cant be resolved.
Where are you getting the doctorList ArrayList? The ArrayList needs to be declared and initialised before you can pass it to the adapter.
TechTev said:
Where are you getting the doctorList ArrayList? The ArrayList needs to be declared and initialised before you can pass it to the adapter.
Click to expand...
Click to collapse
doctorList is declared and initialized in another activity ..
Code:
private DrawerLayout mDrawerLayout;
private Button pButton = null;
private ActionBarDrawerToggle mToggle;
private int noOfDoctors;
public ArrayList<String> doctorList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient_first_screeen);
pButton = (Button) findViewById(R.id.goTODocList);
pButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent (view.getContext(),Doctor_List.class);
startActivity(i);
final String url = <link>;
final JsonArrayRequest getDocList = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onResponse(JSONArray response) {
try {
JSONArray docList = new JSONArray(response);
JSONObject docRow;
noOfDoctors = docList.length();
for (int i=0; i<noOfDoctors; i++) {
docRow = docList.getJSONObject(i);
doctorList.add(i,docRow.getString("name"));
}
Toast.makeText(PatientFirstScreen.this, "Hi brother.", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PatientFirstScreen.this, "List of Doctors can't be retrieved right now. Please try later.", Toast.LENGTH_SHORT).show();
//what to do with error
}
}
);
MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
}}
);
I see. What you need to do is pass the ArrayList as an Extra to the activity. To do this you need to call startActivity after you've done your JSONArray request. Here's an example of what that might look like:
First activity
Code:
private DrawerLayout mDrawerLayout;
private Button pButton = null;
private ActionBarDrawerToggle mToggle;
private int noOfDoctors;
public ArrayList<String> doctorList = new ArrayList<>();
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient_first_screeen);
pButton = (Button) findViewById(R.id.goTODocList);
pButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final String url = <link>;
final JsonArrayRequest getDocList = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@override
public void onResponse(JSONArray response) {
try {
JSONArray docList = new JSONArray(response);
JSONObject docRow;
noOfDoctors = docList.length();
for (int i=0; i<noOfDoctors; i++) {
docRow = docList.getJSONObject(i);
doctorList.add(i,docRow.getString("name"));
}
Toast.makeText(PatientFirstScreen.this, "Hi brother.", Toast.LENGTH_SHORT).show();
// Call start activity here as it depends on the docList.
Intent i = new Intent (view.getContext(),Doctor_List.class);
// Put the String Array List as an extra.
i.putStringArrayListExtra(Doctor_List.EXTRA_DOC_LIST, docList);
startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PatientFirstScreen.this, "List of Doctors can't be retrieved right now. Please try later.", Toast.LENGTH_SHORT).show();
//what to do with error
}
}
);
MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
}}
);
Doctor List Activity
Code:
private ListView docList;
// Key for the extra you are passing to the activity.
public static final String EXTRA_DOC_LIST = "your.package.name.Doc_List.extra_doc_list";
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_doctor__list);
docList = (ListView) findViewById(R.id.docList);
// Get the doctor list extra
ArrayList<String> doctorList = getIntent.getStringArrayListExtra(EXTRA_DOC_LIST);
// The Adapter should now work
docList.setAdapter(new ArrayAdapter<String>(Doctor_List.this, android.R.layout.simple_list_item_1, doctorList));
}
TechTev said:
I see. What you need to do is pass the ArrayList as an Extra to the activity. To do this you need to call startActivity after you've done your JSONArray request. Here's an example of what that might look like:
First activity
Code:
private DrawerLayout mDrawerLayout;
private Button pButton = null;
private ActionBarDrawerToggle mToggle;
private int noOfDoctors;
public ArrayList<String> doctorList = new ArrayList<>();
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient_first_screeen);
pButton = (Button) findViewById(R.id.goTODocList);
pButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final String url = <link>;
final JsonArrayRequest getDocList = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@override
public void onResponse(JSONArray response) {
try {
JSONArray docList = new JSONArray(response);
JSONObject docRow;
noOfDoctors = docList.length();
for (int i=0; i<noOfDoctors; i++) {
docRow = docList.getJSONObject(i);
doctorList.add(i,docRow.getString("name"));
}
Toast.makeText(PatientFirstScreen.this, "Hi brother.", Toast.LENGTH_SHORT).show();
// Call start activity here as it depends on the docList.
Intent i = new Intent (view.getContext(),Doctor_List.class);
// Put the String Array List as an extra.
i.putStringArrayListExtra(Doctor_List.EXTRA_DOC_LIST, docList);
startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PatientFirstScreen.this, "List of Doctors can't be retrieved right now. Please try later.", Toast.LENGTH_SHORT).show();
//what to do with error
}
}
);
MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
}}
);
Doctor List Activity
Code:
private ListView docList;
// Key for the extra you are passing to the activity.
public static final String EXTRA_DOC_LIST = "your.package.name.Doc_List.extra_doc_list";
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_doctor__list);
docList = (ListView) findViewById(R.id.docList);
// Get the doctor list extra
ArrayList<String> doctorList = getIntent.getStringArrayListExtra(EXTRA_DOC_LIST);
// The Adapter should now work
docList.setAdapter(new ArrayAdapter<String>(Doctor_List.this, android.R.layout.simple_list_item_1, doctorList));
}
Click to expand...
Click to collapse
Thanks. But, the arraylist is now accepted in the adapter but now, the button has stopped responding. Looks like the intent is not working now. I can't go the next page.
pk0486 said:
Thanks. But, the arraylist is now accepted in the adapter but now, the button has stopped responding. Looks like the intent is not working now. I can't go the next page.
Click to expand...
Click to collapse
I just checked the code I posted and I made a couple of typos and I think as the activity start call is from within the listener it needs to be Patient_First_Screen.this.startActivity(i).
Try this code:
Code:
private DrawerLayout mDrawerLayout;
private Button pButton = null;
private ActionBarDrawerToggle mToggle;
private int noOfDoctors;
public ArrayList<String> doctorList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient_first_screeen);
pButton = (Button) findViewById(R.id.goTODocList);
pButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final String url = <link>;
final JsonArrayRequest getDocList = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onResponse(JSONArray response) {
try {
JSONArray docList = new JSONArray(response);
JSONObject docRow;
noOfDoctors = docList.length();
for (int i=0; i<noOfDoctors; i++) {
docRow = docList.getJSONObject(i);
doctorList.add(i,docRow.getString("name"));
}
Toast.makeText(PatientFirstScreen.this, "Hi brother.", Toast.LENGTH_SHORT).show();
// Call start activity here as it depends on the docList.
Intent i = new Intent (view.getContext(),Doctor_List.class);
// Put the String Array List as an extra.
i.putStringArrayListExtra(Doctor_List.EXTRA_DOC_LIST, doctorList);
Patient_First_Screen.this.startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PatientFirstScreen.this, "List of Doctors can't be retrieved right now. Please try later.", Toast.LENGTH_SHORT).show();
//what to do with error
}
}
);
MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
}}
);
TechTev said:
I just checked the code I posted and I made a couple of typos and I think as the activity start call is from within the listener it needs to be Patient_First_Screen.this.startActivity(i).
Try this code:
Code:
private DrawerLayout mDrawerLayout;
private Button pButton = null;
private ActionBarDrawerToggle mToggle;
private int noOfDoctors;
public ArrayList<String> doctorList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient_first_screeen);
pButton = (Button) findViewById(R.id.goTODocList);
pButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final String url = <link>;
final JsonArrayRequest getDocList = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onResponse(JSONArray response) {
try {
JSONArray docList = new JSONArray(response);
JSONObject docRow;
noOfDoctors = docList.length();
for (int i=0; i<noOfDoctors; i++) {
docRow = docList.getJSONObject(i);
doctorList.add(i,docRow.getString("name"));
}
Toast.makeText(PatientFirstScreen.this, "Hi brother.", Toast.LENGTH_SHORT).show();
// Call start activity here as it depends on the docList.
Intent i = new Intent (view.getContext(),Doctor_List.class);
// Put the String Array List as an extra.
i.putStringArrayListExtra(Doctor_List.EXTRA_DOC_LIST, doctorList);
Patient_First_Screen.this.startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PatientFirstScreen.this, "List of Doctors can't be retrieved right now. Please try later.", Toast.LENGTH_SHORT).show();
//what to do with error
}
}
);
MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
}}
);
Click to expand...
Click to collapse
Still the same issue .. Can you please explain what is the issue with the code? I didn't understand why did you modify the code?
pk0486 said:
Still the same issue .. Can you please explain what is the issue with the code? I didn't understand why did you modify the code?
Click to expand...
Click to collapse
Sure, I moved the call to start the activity into the JSON response listener as that's when the doctorList is populated which we need to pass to the next activity. As that is in an anonymous inner class it needs to call the instance of the outer class using OuterClassName.this . However you have two inner classes so that's probably why it isn't working.
Maybe try moving the startActivity(i) call and intent creation to below the call to MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
TechTev said:
Sure, I moved the call to start the activity into the JSON response listener as that's when the doctorList is populated which we need to pass to the next activity. As that is in an anonymous inner class it needs to call the instance of the outer class using OuterClassName.this . However you have two inner classes so that's probably why it isn't working.
Maybe try moving the startActivity(i) call and intent creation to below the call to MySingleton.getInstance(PatientFirstScreen.this).addToRequestQueue(getDocList);
Click to expand...
Click to collapse
Got it. Thanks. You were right. But there was some issue with my JSONArray because of which the loop wasn't getting executed. Resolved it now. Thanks again!
pk0486 said:
Got it. Thanks. You were right. But there was some issue with my JSONArray because of which the loop wasn't getting executed. Resolved it now. Thanks again!
Click to expand...
Click to collapse
No problem. Good luck with the rest of your project.
TechTev said:
No problem. Good luck with the rest of your project.
Click to expand...
Click to collapse
Now, I am stuck again. I changed my arraylist to custom array list. I have created the custom array adapter and its fine. I got my JSONArray which I parsed and created the required ArrayList. But when I use this ArrayList as an argument for the custom array adapter, it gives the below error.
https://ibb.co/hhYqOG - this is the link for screenshot of error
Code:
List<DocRow> doctors = new ArrayList<>();
After this, I have assigned values to this ArrayList.
Code:
DocAdapter adapter = new DocAdapter(getApplicationContext(), R.layout.doc_row, doctors);
docList.setAdapter(adapter);
Below is the adapter constructor
Code:
public DocAdapter(@NonNull Context context, @LayoutRes int resource, ArrayList<DocRow> doctors) {
super(context, resource, doctors);
this.context = context;
this.resource = resource;
this.doctors = doctors;
inflater = LayoutInflater.from(context);
What am I missing? Thanks.
pk0486 said:
Now, I am stuck again. I changed my arraylist to custom array list. I have created the custom array adapter and its fine. I got my JSONArray which I parsed and created the required ArrayList. But when I use this ArrayList as an argument for the custom array adapter, it gives the below error.
https://ibb.co/hhYqOG - this is the link for screenshot of error
Code:
List<DocRow> doctors = new ArrayList<>();
After this, I have assigned values to this ArrayList.
Code:
DocAdapter adapter = new DocAdapter(getApplicationContext(), R.layout.doc_row, doctors);
docList.setAdapter(adapter);
Below is the adapter constructor
Code:
public DocAdapter(@NonNull Context context, @LayoutRes int resource, ArrayList<DocRow> doctors) {
super(context, resource, doctors);
this.context = context;
this.resource = resource;
this.doctors = doctors;
inflater = LayoutInflater.from(context);
What am I missing? Thanks.
Click to expand...
Click to collapse
I think it's because you've specifically asked for an arrayList instead of a List as an argument for your custom adapter constructor. Try changing your constructor for the adapter to this:
Code:
public DocAdapter(@NonNull Context context, @LayoutRes int resource, List<DocRow> doctors) {
super(context, resource, doctors);
this.context = context;
this.resource = resource;
this.doctors = doctors;
inflater = LayoutInflater.from(context);