Essential libraries for every android projects

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    

    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'

Android call activity methods from fragment , fragment method from activity and fragment method from fragment in kotlin in Android

1. Call activity method from fragment :

(activity as ActivityName).methodName()
ex:
(activity as MainActivity).userInfo()

2. Call fragment method from activity

  var fragment = supportFragmentManager.findFragmentById(R.id.content) 
  as UserInfoDetailsFragment
  fragment.userInfoDetails()

3. Call fragment method from fragment

UserProfileFragment().userProfile(context)

Android recycler view item click listener from Activity or Fragment

First Create an interface . NotfallKontakteEntity is Model of list items


public interface OnItemClickListener {
    void onItemClick(NotfallKontakteEntity item);
}

Then in adapter define and create constructor with click listener

public  OnItemClickListener listener;

public NotfallKontakteAdapter(List<NotfallKontakteEntity> notfallKontakteEntityList, OnItemClickListener listener) {
this.notfallKontakteEntityList = notfallKontakteEntityList;
this.listener = listener;
}

Now just declare it any click item view OnClickListener . Must add the item position as parameter.

  userHolder.delete.setOnClickListener(new View.OnClickListener() {
   @Override
    public void onClick(View v)
    {
      
   listener.onItemClick(notfallKontakteEntityList.get(position));
           
 }
 });

Now time to user this click listener. We can use anywhere in our fragment or activity

     recyclerView.setAdapter(NotfallKontakteAdapter(contactList, object : OnItemClickListener {
            override fun onItemClick(item: NotfallKontakteEntity) {
               Toast.makeText(context, contactList.id.toString(), Toast.LENGTH_LONG).show()


            }
        }))

Android toggle visible password field easy way

Just paste these code for password edittext field

       <android.support.design.widget.TextInputLayout
            android:id="@+id/txt_pass_layout"
            android:layout_width="0dp"
            android:layout_height="@dimen/count_50dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="32dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="16dp"
            app:passwordToggleEnabled="true"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/txt_Email" >

            <android.support.design.widget.TextInputEditText
                android:id="@+id/txt_pass"
                style="@style/AppTheme.EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/password"
                android:inputType="textPassword"/>
        </android.support.design.widget.TextInputLayout>