ContextMenu replaces Windows right-click on Android app
5 minute(s) read
|
Published on: Aug 18, 2021
Updated on: Dec 14, 2021
|
In Windows operating systems, you can right-click on a folder to delete something, such as deleting, copying, or even renaming it, and then make the changes you want. They do. This option is also required in phone operating systems and Android systems. That is, there must be an option to do all this. The difference between computer systems and Android systems (in German: Android-Systeme ) is that in computer systems, we right-click, and in Android applications we must hold it for a few moments with our finger. In this article, we want to tell you about this option using ContextMenu.
In this part of the article, we want to make changes to the View list using the ContextMenu option, for example, we can edit the names of contacts or contact them and make other changes.
1- We create a new project in Android Studio and choose the desired name.
2- The name chosen for this project in this article is ContextMenu-Gsm.
3- In the first step, we go to Layout.
4- Create a view list in the application layer.
5- The codes listed below are for the view list in this project:
6- Then, we must put all the code related to Java in the MainActivity.java section.
7- Define the view list inside onCreate ().
8- The code added to the end of the onCreate () method is as follows:
We prepare a list of views created for the Context Menu operation by entering this code.
9- Define a new method called onCreateContextMenu that is outside the onCreate () method.
10-Then we create a method called on ContextItemSelected and boolean type so that if we click the relevant button, it can do the relevant work.
11- The full contents of the MainActivity.java section are as follows:
12- We will implement the project.
13- After running the program, we will see that all the items entered will be displayed in the view list.
14- In this case, we can do the things we want to apply to them by pressing one of these.
These are the same right-click options on systems like Windows. To do this in computer systems, we have to right-click, but because Android operating system does not have clicks and their screens are touched, it is not possible to right-click on them, and instead of the right-click option, you must use a finger. Pressed.
So, pressing to do something replaces the right-click option in computer systems.
Transfer between activities using Intent
In this section, we want to tell you how to transfer between activities using Intent. Intents have the duty and responsibility to receive data from the source and transfer it to the destination.
The transition between activities and open windows in Windows operating systems for computer systems using the ALT + TAB key combination this operation in Android systems can also be done with the push of a button. Of course, we must create a button and enter the related codes and commands to finally move to other activities at the push of a button.
1- We create a new project in Android Studio and choose the desired name.
2- The name chosen in this article is for the Intent-Gsm project.
3- In the second step, we must create a button in the application layer. Create and add this button to move to the second activity.
4- The codes that should be included in the section are as follows.
5- Then we add an Activity to our application.
6- Select Empty Activity from the Activity section after clicking the new section.
7- Then a window will open where we must enter the name of the new activity.
8- It is better not to change and register the names entered by Android Studio.
9- Activity Name:
-asks us for the file name that exists in the Java path.
10- Layout Name:
- This section also asks us to enter the name of the application layer.
11- In the last part, we must enter the name of the project package that we entered when creating the project.
12- After following the above steps, we must select the Finish button.
13- We need to add a TextView to the layout section in activity_main2.xml.
14- In this article, we name TextView Activity 2.
15- The cells in the Layout section of the second activity are as follows.
16- In the first activity, we have created a button that we can click on to move to the second activity. We need to enter the related code to move from one activity to another by clicking on the created button.
17- Open the MainActivity.java file to apply the changes.
18- We must introduce the created button to the onCreate () method.
19- We also add an onClickListener event to the Button.
20- To transfer from the second activity to the first activity, we must also enter the relevant codes.
By entering the above code and using startActivity, we can move and move between activities.
21- Define and create a new Intent for the startActivity input using the New Intent command. It should be noted that this Intent has two arguments.
22- The complete code that should be in the MainActivity.java section is as follows.
23- We will implement the project.
24- When I run the program, we will see that we are in the first activity, and if we click on the button, we will be transferred to the second activity.
About our Android and iOS app development services