Created
September 4, 2020 06:04
-
-
Save Vishal023/cfbec174ef32300339a5e3ce06669a55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:padding="20dp" | |
android:weightSum="1" | |
tools:context=".OddSetAssignment"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_weight="0.5" | |
android:orientation="vertical"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:paddingTop="30dp" | |
android:paddingBottom="110dp" | |
android:weightSum="1"> | |
<LinearLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight=".5" | |
android:orientation="horizontal"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="BOOK" | |
android:textSize="18sp" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight="0.5" | |
android:orientation="vertical"> | |
<CheckBox | |
android:id="@+id/dsBook" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="DS" | |
android:textStyle="bold" /> | |
<CheckBox | |
android:id="@+id/androidBook" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="ANDROID" | |
android:textStyle="bold" /> | |
<CheckBox | |
android:id="@+id/javaBook" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="JAVA" | |
android:textStyle="bold" /> | |
</LinearLayout> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:paddingBottom="10dp" | |
android:weightSum="1"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingLeft="50dp" | |
android:paddingRight="5dp" | |
android:text="TITLE" | |
android:textSize="14sp" | |
android:textStyle="bold" /> | |
<EditText | |
android:id="@+id/title" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:ems="10" | |
android:hint="Tom"/> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:paddingBottom="10dp"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingLeft="30dp" | |
android:paddingRight="5dp" | |
android:text="AUTHOR" | |
android:textSize="14sp" | |
android:textStyle="bold" /> | |
<EditText | |
android:id="@+id/author" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:ems="10" | |
android:hint="Tom"/> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="horizontal"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="TRANSLATOR" | |
android:textSize="14sp" | |
android:textStyle="bold" /> | |
<ListView | |
android:id="@+id/langList" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> | |
</LinearLayout> | |
</LinearLayout> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_weight="0.5" | |
android:orientation="vertical"> | |
<ImageView | |
android:id="@+id/img" | |
android:layout_width="match_parent" | |
android:layout_height="183dp" | |
app:srcCompat="@mipmap/ic_launcher" /> | |
<Button | |
android:id="@+id/menuButton" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="end" | |
android:layout_marginTop="10dp" | |
android:text="Menu" /> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="10dp" | |
android:orientation="horizontal" | |
android:weightSum="1"> | |
<LinearLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight="0.5" | |
android:orientation="horizontal"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:gravity="center" | |
android:text="Lonable" | |
android:textSize="24sp" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight="0.5" | |
android:orientation="horizontal"> | |
<RadioGroup | |
android:id="@+id/lonableGroup" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="end"> | |
<RadioButton | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="20dp" | |
android:text="YES" | |
android:textSize="16sp" /> | |
<RadioButton | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="NO" | |
android:textSize="16sp" /> | |
</RadioGroup> | |
</LinearLayout> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="10dp" | |
android:gravity="center" | |
android:orientation="horizontal"> | |
<Button | |
android:id="@+id/btnCancel" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="CANCEL" /> | |
<Button | |
android:id="@+id/btnAdd" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="ADD" /> | |
</LinearLayout> | |
</LinearLayout> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.myapp; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.ArrayAdapter; | |
import android.widget.Button; | |
import android.widget.CheckBox; | |
import android.widget.EditText; | |
import android.widget.RadioButton; | |
import android.widget.RadioGroup; | |
import android.widget.Spinner; | |
import android.widget.Toast; | |
import java.util.regex.Pattern; | |
public class EvenSetAssignment extends AppCompatActivity { | |
Button login,cancel; | |
EditText age,name; | |
RadioGroup rg; | |
RadioButton radioButton; | |
Spinner spinner; | |
CheckBox dance,poetry,sports; | |
int selectedRadio; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_even_set_assignment); | |
String[] arr = {"Music","Classical","Rock","Jazz"}; | |
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this,R.layout.support_simple_spinner_dropdown_item,arr); | |
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | |
spinner = findViewById(R.id.spinner); | |
spinner.setAdapter(arrayAdapter); | |
login = findViewById(R.id.login); | |
cancel = findViewById(R.id.cancelBtn); | |
age = findViewById(R.id.age); | |
name = findViewById(R.id.user_name); | |
rg = findViewById(R.id.genderGroup); | |
dance = findViewById(R.id.dance); | |
poetry = findViewById(R.id.poetry); | |
sports = findViewById(R.id.sports); | |
login.setEnabled(false); | |
age.addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { } | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
if (!s.toString().equals("")){ | |
int ageVal = Integer.parseInt(s.toString()); | |
if (ageVal >= 18){ | |
login.setEnabled(true); | |
}else { | |
login.setEnabled(false); | |
} | |
} | |
} | |
@Override | |
public void afterTextChanged(Editable s) {} | |
}); | |
login.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
selectedRadio = rg.getCheckedRadioButtonId(); | |
radioButton = findViewById(selectedRadio); | |
String user = name.getText().toString(); | |
if (user.equals("")) { | |
toastFunction("Enter your name!!"); | |
}else if (!user.matches("[a-zA-Z][a-zA-Z ]+")){ | |
toastFunction("Name must contain alphabets only"); | |
}else if (selectedRadio == -1){ | |
toastFunction("Select your gender"); | |
}else if (!dance.isChecked() && !poetry.isChecked() && !sports.isChecked()){ | |
toastFunction("Select at least one hobby"); | |
}else{ | |
toastFunction("Submitted the record"); | |
} | |
} | |
}); | |
cancel.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
name.setText(""); | |
age.setText(""); | |
rg.clearCheck(); | |
spinner.setSelection(0); | |
dance.setChecked(false); | |
poetry.setChecked(false); | |
sports.setChecked(false); | |
login.setEnabled(false); | |
toastFunction("Cancelled"); | |
} | |
}); | |
} | |
public void toastFunction(String toastText){ | |
Toast.makeText(getApplicationContext(),toastText,Toast.LENGTH_SHORT).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment