Select Images Then Button Click validation

 

   

Java code
package com.rebliss.newrebliss;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class ActivityPersnalDetails extends AppCompatActivity implements View.OnClickListener {
EditText firstname, lastname;
LinearLayout male, female, othergender,malebtn,femalebtn,otherbtn;
Button btn_next3;
Bundle bundle = new Bundle();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_persnal_details);
firstname = findViewById(R.id.firstname);
lastname= findViewById(R.id.lastname);
btn_next3= findViewById(R.id.btnNext3);
male = findViewById(R.id.male);
female = findViewById(R.id.female);
othergender = findViewById(R.id.othergender);
malebtn=findViewById(R.id.malebtn);
femalebtn=findViewById(R.id.femalebtn);
otherbtn=findViewById(R.id.otherbtn);
male.setOnClickListener(this);
female.setOnClickListener(this);
othergender.setOnClickListener(this);
otherbtn.setEnabled(false);
malebtn.setEnabled(false);
femalebtn.setEnabled(false);
btn_next3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String FirstName = firstname.getText().toString();
String LastName = lastname.getText().toString();

if (FirstName.isEmpty()) {
firstname.requestFocus();
firstname.setError("please enter your First Name");
return;

} else if (LastName.isEmpty()) {
lastname.requestFocus();
lastname.setError("please enter your Last Name");
return;
} else {
try {

bundle.putString("firstname",FirstName);
bundle.putString("lastname",LastName);

} catch (Exception ex) {
Toast.makeText(getApplicationContext(), "Message : " + ex.getMessage(), Toast.LENGTH_SHORT).show();

}
}



if (malebtn.isEnabled()||femalebtn.isEnabled()||otherbtn.isEnabled())
{
Intent intent=new Intent(getApplicationContext(),PracticeActivity.class);
intent.putExtras(bundle);
startActivity(intent);

}
else {

Toast.makeText(getApplicationContext(),"Please Selct One",Toast.LENGTH_SHORT).show();


}

//// finish();

}
});


}

@Override
public void onClick(View view) {
switch (view.getId()){

case R.id.male:

bundle.putString("male","Male");
bundle.remove("female");
bundle.remove("othergender");
malebtn.setEnabled(true);
femalebtn.setEnabled(false);
otherbtn.setEnabled(false);
male.setBackgroundResource(R.color.startColor);
female.setBackgroundResource(R.drawable.corner_button);
othergender.setBackgroundResource(R.drawable.corner_button);
break;

case R.id.female:

bundle.putString("female","Female");
bundle.remove("male");
bundle.remove("othergender");
femalebtn.setEnabled(true);
malebtn.setEnabled(false);
otherbtn.setEnabled(false);
female.setBackgroundResource(R.color.startColor);
male.setBackgroundResource(R.drawable.corner_button);
othergender.setBackgroundResource(R.drawable.corner_button);
break;

case R.id.othergender:

bundle.putString("othergender","Other Gender");
bundle.remove("female");
bundle.remove("male");
otherbtn.setEnabled(true);
malebtn.setEnabled(false);
femalebtn.setEnabled(false);
othergender.setBackgroundResource(R.color.startColor);
female.setBackgroundResource(R.drawable.corner_button);
male.setBackgroundResource(R.drawable.corner_button);

break;
}

}
}



xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".ActivityPersnalDetails">

<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/toolbarimg1">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:src="@drawable/ic_baseline_arrow_back_24"
app:tint="@color/white" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginRight="10dp"
android:text="1/9"
android:textColor="@color/white">
</TextView>

</androidx.appcompat.widget.Toolbar>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="45dp"
android:text="@string/name"
android:textColor="@color/black"
android:textSize="30sp"
android:textStyle="bold" />


<EditText
android:id="@+id/firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="38dp"
android:layout_marginTop="20dp"
android:layout_marginRight="38dp"
android:background="@drawable/corner_button"
android:hint="@string/fname"
android:inputType="textPersonName"
android:padding="15dp" />


<EditText
android:id="@+id/lastname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="38dp"
android:layout_marginTop="20dp"
android:layout_marginRight="38dp"
android:background="@drawable/corner_button"
android:hint="@string/lname"
android:inputType="textPersonName"
android:padding="15dp" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="@string/gender"
android:textColor="@color/black"
android:textSize="25sp"
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:weightSum="3"
android:orientation="horizontal">

<LinearLayout
android:id="@+id/malebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:weightSum="1"
android:orientation="vertical">

<LinearLayout

android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">

<LinearLayout
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/corner_button"
android:orientation="vertical">

<ImageView
android:id="@+id/imgMale"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:src="@drawable/male" />
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/male"
android:textColor="@color/black"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:id="@+id/femalebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_marginRight="9dp"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">

<LinearLayout
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/corner_button"
android:orientation="vertical">

<ImageView
android:id="@+id/Female"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:src="@drawable/female" />
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/female"
android:textColor="@color/black"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:id="@+id/otherbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1"
android:layout_marginRight="9dp"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">

<LinearLayout
android:id="@+id/othergender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/corner_button"
android:orientation="vertical">

<ImageView
android:id="@+id/others"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:src="@drawable/othergen" />
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/other"
android:textColor="@color/black"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnNext3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:background="@drawable/corner_button1"
android:text="@string/nextbtn"
android:textAllCaps="false"
android:textColor="@color/white">

</androidx.appcompat.widget.AppCompatButton>

</LinearLayout>


Comments

Popular posts from this blog

Open the Camera Pic The Image send to Server Base64

Spinner select validation