In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people have no idea about how to build terminal programs through Android Studio in Java. Therefore, this paper summarizes the causes and solutions of the problems. Through this article, I hope you can solve this problem.
I. create a project 1.1 create a project
Open android studio to create the project, which is written in Java:
Click "Create new project" on the initial interface
Select an empty active and click next
The above figure shows the project name, package name, project storage location, development language, minimum SDK version, and whether to use previous library files (not recommended). Finally, click the Finish button to confirm.
The system automatically downloads some new library files. So we need to connect to the Internet.
Finally, the project structure is as follows. Of course, there is only one MainActive.java and only one activ_main.xml. The following is a screenshot of two pages I created:
1.2 apply for network permissions
Add the application code for network permission, because the program needs to connect to the remote server, as follows:
1.3 write the first page
The code of the page corresponds to the XML of the page, as shown below, and the MainActivity.java corresponds to active_main.xml.
Of course, the page XML document that can also be bound in MainActivity.java can be changed as follows.
1.3.1 Code for MainActivity.java
As follows:
Note that the package of okhttp3 is needed in the above figure, which needs to be set up first. Double-click build.gradle in the following figure:
Add a line of package code to import okhttp at the bottom of the document:
At this time, the okhttp plug-in is still not available, so you need to refresh the synchronization gradle.
Or this immediately synchronizes the Sync now:
If you still can't, you can clean the cache and restart the program.
After restarting the development environment, wait for gradle to download the corresponding package automatically.
1.3.2 Design and code of xml
As follows:
1.4 write the second page
Right-click com.example.myapplication to create a new interface. As follows, the system automatically creates a new java file and a matching xml file.
As shown below, Activity Name represents the name of the java document, LayoutName represents the name of the interface XML, language selection Java, and finally click Finish.
1.4.1 Java document coding
As follows:
1.4.2 Interface XML Design and Code
As follows:
The code is as follows:
Second, simulated operation
Note that the premise of running is that the project mentioned above is working properly and that the IP address and port can be accessed properly.
2.1 connection Simulator
The MuMu simulator is used here. After starting the simulator, open Android Studio and connect the simulator to android studio with windows's cmd command box.
At this point, we can see that the android studio shows that the simulator exists.
Note that adb.exe is a program in android sdk, and if the cmd prompt cannot find the command, it is because the android sdk environment variable is not configured. Add these two folder paths under the root of android sdk to the system variable path. Note, please check the "sdk root directory" on your computer below.
Sdk root directory / platform-tools and sdk root directory / sdk/tools
2.2 start the simulator
Click the green arrow or press the shortcut key shift+10 to load the program into the simulator to run.
Wait for a success prompt to appear at the bottom:
If you open even log, you can also see the success prompt:
Third, effect
At this time, the interface for switching to the simulator is as follows:
3.1 initial interface
Note that you can switch screen rotation in the "more" of the simulator to avoid sometimes the interface is not complete (of course, this has something to do with your interface design).
3.2 example 1 operation
Fill in the content:
Click the check-in button to see a change in the content of the text label:
If the input is empty, an error message is reported:
3.3 example 2 operation
After clicking the jump example 2 button in interface 1, you can jump to interface 2.
Enter the normal content and click check-in, you can see that the text label of the interface has changed:
If there is a non-null value, an error is prompted:
Click the back button in the image above to return to interface 1.
Click the box button below in android studio to stop running, or use the shortcut key.
After reading the above, have you mastered how to build terminal programs through Android Studio in Java? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.