![]() ![]() We select the package name when creating the application at the start.Īfter creating, the package name automatically shows at the top of each Java source file. The package name shows the unique identity of the application. ![]() Package import android.os.Bundle import 7.app.AppCompatActivity import import import public class MainActivity extends AppCompatActivity Īfter pressing the button on the screen, the Toast shows the following:Īll records are deleted in SQLite database successfully.Įxplanation of the mainActivity.java file: Now, create a java file named mainActivity.java to connect the UI (xml file) to the functionality by connecting the widgets. This id differentiates between different widgets when communicating with the Java source file. For each widget inside the constraintLayout, we need to set the unique id by using the property android:id. The default text on the Button widget is button, so we can replace it with our text, Delete All Rows, using the property android:text. ![]() The value wrap_content for width and height shows that the Button layout takes the width the same as the length of the text written on the Button layout. We need to import the Button inside the main (parent) layout, which is constraintLayout.įor the Button widget, we use different properties: the layout’s width and height. Later, we need a button to perform the delete functionality. The value for both properties is set to match_parent, which shows that the main (parent) layout takes 100 percent of the available width and height of the screen. Inside the constraintLayout, two properties, android:layout_width and android:layout_height, are used to set the width and height of the layout, respectively. This constraintLayout is available on Android API version 9 (Gingerbread) and above. This layout allows you to size and flexibly position the widget in a ViewGroup. In this example, we use the constraintLayout to create the layout in the XML. In android, we create layouts using widgets like Linear Layout, Relative Layout, Constraint Layout, etc. Explanation of the mainActivity.xml file: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |