Skip to main content

Posts

Floating Context Menu

In this tutorial, we will learn how to create a floating context menu, which will appear when we long click on a particular view or item. For this we will create a menu xml file, override onCreateContextMenu to inflate this menu, use the registerForContextMenu method to set it on a TextView and finally handle clicks by overriding onContextItemSelected and check for the ID of the clicked item. Lastly we will learn, how to add a header title to our floating context menu by using the setHeaderTitle method. In activity_main.xml add these lines of code:- <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:conte...

Popup Menu

In this tutorial we will create a simple PopupMenu and handle it’s click events using the setOnMenuItemClickListener method. Follow this step:- In activity_main.xml add these lines of codes:- <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.example.application.popupproject.MainActivity">     <Button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:onClick="showPopup"         android:text="show popup"         app:layout_constraintBo...

Cloud Firestore

Part 1 – Introduction Part 2 – Preparations & Set Document Part 3 – Get Document Part 4 – SnapshotListener Part 5 – Merge & Update Part 6 – Delete Field & Document Part 7 – Custom Objects Part 8 – Add & Retrieve Multiple Documents Part 9 – Simple Queries Part 10 – Compound Queries Part 11 – OR Queries Part 12 – Pagination Part 13 – DocumentChanges Part 14 – Batched Writes Part 15 – Transactions Part 16 – Arrays Part 17 – Nested Objects Part 18 – Subcollections                  Part 1 – Introduction In this tutorial we will learn , how to use the Cloud Firestore database to store and retrieve data in an Android app. Firestore is a cloud-hosted database that makes it easy to synchronize data in realtime between multiple connected client apps and across different platforms, without us having to manage our own servers. Firestore is a schemaless NoSQL database and stores ...

Options Menu with Sub Items

In this tutorial  we will create an options menu in Android Studio, which contains icons, drop down menus and sub items. The menu will be displayed in the app bar. For this we will override onCreateOptionsMenu and pass our own menu.xml file. Also we will handle click events on the single items in the onOptionsItemSelected method. In MainActivity.java class file add these lines of codes:- import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; public class MainActivity extends AppCompatActivity {     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);     }     @Override     public boolean onCreateOptionsMenu(Menu menu) { ...

Up Button

In this tutorial we are going to implement an up/back button into our app, which navigates us back to our parent Activity.  For this we have to make some small changes in our Manifest.xml file. In manifest.xml file add these lines of code:- <activity  android:name=".Activity2"                android:parentActivityName=".MainActivity"></activity> <activity  android:name=".Activity3"                android:parentActivityName=".Activity2"></activity> In MainActivity.java class file add these lines of codes:- import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity {     private Button button;     @Override     protected void onCreate(Bundle savedInstanceSta...