page is not getting intended when button is clicked - android

So basically when I will click the register button it should direct me to the next page that is the three_section page.I too wrote the code for this also I have actually added validations to the page,But the button is getting clicked but it is not taking me next page.I mean next page is not getting opened.There is no error in the logcat section coming .It means my code is running ..But the page is not getting intended i.e. there is somewhere some bug.I tried solving but I am mot gettting it.
this is my new_user_register.java code
public class new_user_register extends AppCompatActivity {
EditText name1;
EditText email1;
EditText usname1;
EditText password1;
Button register;
ToastManager toastManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_user_register);
name1 = (EditText) findViewById(R.id.name1);
email1 = (EditText) findViewById(R.id.email1);
usname1 = (EditText) findViewById(R.id.usname1);
password1 = (EditText) findViewById(R.id.password1);
register = (Button) findViewById(R.id.register);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String NAME = name1.getText().toString().trim();
String EMAIL = email1.getText().toString().trim();
String username = usname1.getText().toString().trim();
String password = password1.getText().toString().trim();
String emailPattern = "^[a-zA-Z0-9+_.-]{3,32}+#[a-zA-Z0-9.-]{2,32}+$";
boolean isAtLeastOneFieldNotEmpty = !NAME.isEmpty()
|| !EMAIL.isEmpty()
|| !username.isEmpty()
|| !password.isEmpty();
toastManager = new ToastManager(new_user_register.this);
// You have 5 registration fields that users must fill up.
final int totalRegistrationField = 5;
// This will increase by 1 when a field is valid
int validRegistrationFieldCount = 0;
if (isAtLeastOneFieldNotEmpty) {
// NAME VALIDATION
if (NAME.isEmpty()) {
toastManager.addToast("ENTER NAME", ToastManager.Duration.LENGTH_SHORT);
} else if (!((NAME.length() > 3) && (NAME.length() < 15))) {
toastManager.addToast("NAME IS TOO SHORT.IT MUST BE BETWEEN 3-15 CHARACTERS.", ToastManager.Duration.LENGTH_SHORT);
} else if (!NAME.matches("[a-zA-Z ]+")) {
toastManager.addToast("ONLY ALPHABETS ALLOWED", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
// EMAIL VALIDATION
if (EMAIL.isEmpty()) {
toastManager.addToast("ENTER EMAIL-ID", ToastManager.Duration.LENGTH_SHORT);
} else if (!(EMAIL.matches(emailPattern))) {
toastManager.addToast("INVALID EMAIL", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
// USERNAME VALIDATION
if (username.isEmpty()) {
toastManager.addToast("ENTER USERNAME", ToastManager.Duration.LENGTH_SHORT);
} else if (!((username.length() > 6) && (username.length() < 15))) {
toastManager.addToast("USERNAME IS TOO SHORT.IT MUST BE BETWEEN 6-15 CHARACTERS.", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
// PASSWORD VALIDATION
if (password.isEmpty()) {
toastManager.addToast("ENTER PASSWORD", ToastManager.Duration.LENGTH_SHORT);
} else if (!((password.length() > 6) && (password.length() < 15))) {
toastManager.addToast("PASSWORD IS TOO SHORT.IT MUST BE BETWEEN 6-15 CHARACTERS.", ToastManager.Duration.LENGTH_SHORT);
} else {
++validRegistrationFieldCount;
}
} else {
toastManager.addToast("ALL FIELDS ARE COMPULSORY", ToastManager.Duration.LENGTH_SHORT);
}
if (validRegistrationFieldCount != totalRegistrationField) {
// Finally show all toast all screen
toastManager.show();
} else {
// All registration fields are valid, then go to another screen.
Intent p = new Intent(new_user_register.this, three_sections.class);
startActivity(p);
}
}
});
}
}
this is my new_user_register.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".loginpage"
android:background="#drawable/ic_launcher_background">
<TextView
android:layout_width="216dp"
android:layout_height="68dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginEnd="128dp"
android:layout_marginBottom="561dp"
android:text="NEW USER REGISTRATION"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold|italic"
android:typeface="sans" />
<TextView
android:id="#+id/textView"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="207dp"
android:layout_marginBottom="277dp"
android:drawableLeft="#drawable/username_foreground"
android:text="USERNAME"
android:textColor="#color/Purple"
android:textSize="20dp" />
<TextView
android:id="#+id/name"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="256dp"
android:layout_marginBottom="501dp"
android:drawableLeft="#drawable/username_foreground"
android:text="NAME"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:id="#+id/name1"
android:layout_width="291dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="80dp"
android:layout_marginBottom="434dp"
android:hint="ENTER NAME" />
<TextView
android:id="#+id/email"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="229dp"
android:layout_marginBottom="386dp"
android:drawableLeft="#drawable/password_foreground"
android:text="EMAIL ID"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:id="#+id/email1"
android:layout_width="289dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="87dp"
android:layout_marginBottom="326dp"
android:hint="ENTER EMAIL ID" />
<EditText
android:id="#+id/usname1"
android:layout_width="292dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="85dp"
android:layout_marginBottom="220dp"
android:hint="ENTER USERNAME" />
<TextView
android:id="#+id/t3"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="184dp"
android:layout_marginBottom="170dp"
android:drawableLeft="#drawable/password_foreground"
android:text="PASSWORD"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:id="#+id/password1"
android:layout_width="286dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="88dp"
android:layout_marginBottom="113dp"
android:hint="ENTER PASSWORD" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="525dp"
android:src="#drawable/imaagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="408dp"
android:src="#drawable/image" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="292dp"
android:src="#drawable/iimagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="176dp"
android:src="#drawable/imagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="61dp"
android:src="#drawable/imageee" />
<Button
android:id="#+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="210dp"
android:layout_marginBottom="43dp"
android:background="#android:color/transparent"
android:text="REGISTER"
android:textColor="#color/Purple"
android:textSize="25dp" />
</RelativeLayout>
this is my three_section xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".three_sections">
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="429dp"
android:alpha="0.4"
android:background="#color/Purple" />
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-14dp"
android:layout_marginBottom="472dp"
android:freezesText="true"
android:text=" BEGINNERS CALLIGRAPHY"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="238dp"
android:alpha="0.4"
android:background="#color/DeepPink" />
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-27dp"
android:layout_marginBottom="90dp"
android:text=" ADVANCED CALLIGRAPHY"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="47dp"
android:alpha="0.4"
android:background="#color/DarkBlue" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="315dp"
android:freezesText="true"
android:text=" INTERMEDIATE CALLIGRAPHY"
android:textSize="25dp" />
</RelativeLayout>

Your code is never go inside the intent block since your totalRegistrationField and validRegistrationFieldCount never match.
You've assigned value 5 to `totalRegistrationField, and you just increment the validRegistrationFieldCount 4 times.
All what you just need is change totalRegistrationField value to 4.
final int totalRegistrationField = 4;

Related

Button click is not redirecting to next page

So, the problem I am facing over here is when I click on the login button it should redirect to the three_sections page but that is not happening. Same I did with the sign-in now but that worked. Clicking on the sign-in now button is redirecting me to the next page. But the login button is not! I have attached all the code below.
This is my loginpage.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".loginpage"
android:background="#drawable/ic_launcher_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginEnd="152dp"
android:layout_marginBottom="549dp"
android:text="USER LOGIN"
android:textColor="#color/black"
android:textSize="30dp"
android:typeface="sans" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="37dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="205dp"
android:layout_marginBottom="449dp"
android:text="USERNAME"
android:drawableLeft="#drawable/username_foreground"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:layout_width="283dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="88dp"
android:layout_marginBottom="393dp"
android:hint="ENTER USERNAME" />
<TextView
android:id="#+id/t3"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="200dp"
android:layout_marginBottom="340dp"
android:text="PASSWORD"
android:drawableLeft="#drawable/password_foreground"
android:textColor="#color/Purple"
android:textSize="20dp" />
<EditText
android:layout_width="284dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="85dp"
android:layout_marginBottom="273dp"
android:hint="ENTER PASSWORD" />
<Button
android:id="#+id/login"
android:layout_width="161dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="163dp"
android:layout_marginBottom="188dp"
android:background="#android:color/transparent"
android:text="LOGIN"
android:textColor="#color/Purple"
android:textSize="20dp" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="525dp"
android:src="#drawable/imaagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="408dp"
android:src="#drawable/image" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="292dp"
android:src="#drawable/iimagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="176dp"
android:src="#drawable/imagee" />
<ImageView
android:layout_width="100dp"
android:layout_height="110dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-15dp"
android:layout_marginBottom="61dp"
android:src="#drawable/imageee" />
<Button
android:id="#+id/signnow"
android:layout_width="188dp"
android:layout_height="58dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="143dp"
android:layout_marginBottom="119dp"
android:background="#android:color/transparent"
android:text="SIGN IN NOW"
android:textColor="#color/Purple"
android:textSize="20dp" />
</RelativeLayout>
This is my loginpage.java class
public class loginpage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginpage);
TextView signnow = (TextView) findViewById(R.id.signnow);
signnow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent p = new Intent(loginpage.this,new_user_register.class);
startActivity(p);
}
});
TextView login = (TextView) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(loginpage.this,three_sections.class);
startActivity(i);
}
});
}
}
This is my three_sections.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".three_sections"
>
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="429dp"
android:alpha="0.4"
android:background="#color/Purple" />
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-14dp"
android:layout_marginBottom="472dp"
android:freezesText="true"
android:text=" BEGINNERS CALLIGRAPHY"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="238dp"
android:alpha="0.4"
android:background="#color/DeepPink" />
<TextView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-27dp"
android:layout_marginBottom="90dp"
android:text=" ADVANCED CALLIGRAPHY"
android:textSize="25dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="47dp"
android:alpha="0.4"
android:background="#color/DarkBlue" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="315dp"
android:freezesText="true"
android:text=" INTERMEDIATE CALLIGRAPHY"
android:textSize="25dp" />
</RelativeLayout>
// in OnCreate in loginpage.java
Button signNow = (Button)findViewById(R.id.signnow);
mClickButton1.setOnClickListener(this);
Button login = (Button)findViewById(R.id.clickButton2);
mClickButton2.setOnClickListener(this);
// somewhere else in your code
public void onClick(View v) {
switch (v.getId()) {
case R.id.clickButton1: {
// do something for button 1 click for example
Intent intent = new Intent(this, signNow.class);
startActivity(intent);
break;
}
case R.id.clickButton2: {
// do something for button 2 click
break;
}
}
}
Kotlin Code
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class LoginPage : AppCompatActivity(), View.OnClickListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login_page)
//for sign button click listener
val signNow = findViewById<View>(R.id.signnow) as Button
signNow.setOnClickListener(this)
//for login button click listener
val login = findViewById<View>(R.id.login) as Button
login.setOnClickListener(this)
}
override fun onClick(v: View) {
when (v.id) {
R.id.signnow -> {
// Navigate to New User Register screen.
startActivity(Intent(this, NewUserRegister::class.java))
}
R.id.login -> {
// Navigate to Three Section screen.
startActivity(Intent(this, ThreeSections::class.java))
}
}
}
}
Just change the type cast of your TextView to Button in your loginpage.java code.
Change this
TextView login = (TextView) findViewById(R.id.login);
To this
Button login = (Button) findViewById(R.id.login);

giving error in validation in android studio

While running this code error is coming in the logact section.I guess its minor error so its difficult for me to search the error.I tried various things but it didn't worked for me.I don't know where my code went wrong.
this is my NewUserActivity .java code
public class NewUserActivity extends AppCompatActivity {
EditText name;
EditText email;
EditText phone;
EditText usname;
EditText passsword;
Button register;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_user_login);
name = (EditText) findViewById(R.id.name);
email = (EditText) findViewById(R.id.email);
phone = (EditText) findViewById(R.id.phone);
usname = (EditText) findViewById(R.id.usname);
passsword = (EditText) findViewById(R.id.passsword);
register= (Button) findViewById(R.id.textView2);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String NAME = name.getText().toString().trim();
String EMAIL = email.getText().toString().trim();
String PHONENO =phone.getText().toString().trim();
String username = usname.getText().toString().trim();
String password = passsword.getText().toString().trim();
if (NAME.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter name",Toast.LENGTH_SHORT).show();
else if(EMAIL.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter correct email address",Toast.LENGTH_SHORT).show();
else if(PHONENO.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter correct phone number",Toast.LENGTH_SHORT).show();
else if(username.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter Username",Toast.LENGTH_SHORT).show();
else if(username.length()<8|| username.length()>15)
Toast.makeText(getApplicationContext(),"Username must contain atleast 8 characters",Toast.LENGTH_SHORT).show();
else if(password.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter Password",Toast.LENGTH_SHORT).show();
else if(password.length()<6|| password.length()>10)
Toast.makeText(getApplicationContext(),"Password must contain 6 characters",Toast.LENGTH_SHORT).show();
else {
}
}
});
}
}
this is my xnl file for the same.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
tools:context=".NewUserActivity"
android:background="#drawable/ic_launcher_background"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textView4"
android:layout_width="276dp"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="106dp"
android:layout_marginBottom="581dp"
android:text="REGISTRATION "
android:textColor="#color/WhiteSmoke"
android:textSize="30dp" />
<EditText
android:layout_height="26dp"
android:layout_width="297dp"
android:layout_marginBottom="487dp"
android:layout_marginEnd="65dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/name"/>
<TextView
android:id="#+id/textView5"
android:layout_width="218dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="135dp"
android:layout_marginBottom="530dp"
android:drawableLeft="#drawable/ic_action_name"
android:text="NAME"
android:textColor="#color/WhiteSmoke"
android:textSize="20dp" />
<TextView
android:id="#+id/textView6"
android:layout_width="195dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="161dp"
android:layout_marginBottom="439dp"
android:drawableLeft="#drawable/ic_action_mail"
android:text="EMAIL ID"
android:textColor="#color/WhiteSmoke"
android:textSize="20dp" />
<EditText
android:layout_height="26dp"
android:layout_width="297dp"
android:layout_marginBottom="399dp"
android:layout_marginEnd="67dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/email"/>
<TextView
android:id="#+id/textView7"
android:layout_width="147dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="209dp"
android:layout_marginBottom="351dp"
android:drawableLeft="#drawable/ic_action_phone"
android:text="PHONE NO."
android:textColor="#color/WhiteSmoke"
android:textSize="20dp" />
<EditText
android:layout_width="297dp"
android:layout_height="26dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="63dp"
android:layout_marginBottom="306dp"
android:id="#+id/phone"/>
<TextView
android:layout_height="30dp"
android:layout_width="195dp"
android:textSize="20dp"
android:textColor="#color/WhiteSmoke"
android:text="USERNAME"
android:layout_marginBottom="256dp"
android:layout_marginEnd="160dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/textView8"
android:drawableLeft="#drawable/ic_action_username"/>
<EditText
android:layout_height="26dp"
android:layout_width="297dp"
android:layout_marginBottom="205dp"
android:layout_marginEnd="63dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/usname"/>
<TextView android:layout_height="30dp" android:layout_width="195dp"
android:textSize="20dp" android:textColor="#color/WhiteSmoke"
android:text="PASSWORD" android:layout_marginBottom="160dp"
android:layout_marginEnd="156dp" android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" android:id="#+id/textView9"
android:drawableLeft="#drawable/ic_action_password"/>
<EditText
android:layout_width="297dp"
android:layout_height="26dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="62dp"
android:layout_marginBottom="113dp"
android:id="#+id/passsword"/>
<androidx.cardview.widget.CardView
android:layout_height="56dp" android:layout_width="348dp"
android:layout_marginBottom="40dp" android:layout_marginEnd="20dp"
android:layout_alignParentBottom="true" android:layout_alignParentEnd="true"
app:cardElevation="10dp" app:cardCornerRadius="30dp"
app:cardBackgroundColor="#color/DeepPink" android:layout_marginRight="28dp"
android:layout_marginStart="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true">
<RelativeLayout android:layout_height="73dp" android:layout_width="373dp"
android:layout_marginBottom="100dp" android:layout_marginEnd="50dp">
<Button
android:id="#+id/register"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="129dp"
android:layout_marginBottom="17dp"
android:fontFamily="sans-serif"
android:freezesText="true"
android:text="REGISTER"
android:background="#android:color/transparent"
android:textColor="#color/Black"
android:textSize="24dp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
There is error in this section of my code.
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String NAME = name.getText().toString().trim();
String EMAIL = email.getText().toString().trim();
String PHONENO =phone.getText().toString().trim();
String username = usname.getText().toString().trim();
String password = passsword.getText().toString().trim();
You are using Wrong id of button which will led to the null pointer exception
Change this
register= (Button) findViewById(R.id.textView2);
to
register= (Button) findViewById(R.id.register);
To know about null pointer exception check this
What is a NullPointerException, and how do I fix it?
You can use View binding to replaces all findviewbyId
https://developer.android.com/topic/libraries/view-binding
name = (EditText) findViewById(R.id.name);
email = (EditText) findViewById(R.id.email);
phone = (EditText) findViewById(R.id.phone);
usname = (EditText) findViewById(R.id.usname);
passsword = (EditText) findViewById(R.id.passsword);
register= (Button) findViewById(R.id.textView2);
here check the register button id you add textView2 id here your mistake

NullPointerException on setContentView

I am having two layouts in same xml file and I have kept one layout as hidden and want to show this hidden layout on button click. But when I try to load this activity, it gives me exception on setContentView.
Here is my layout:
<androidx.drawerlayout.widget.DrawerLayout 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:id="#+id/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>
and here is my Java Code:
public class Auftrag extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout eDrawerlayout;
private ActionBarDrawerToggle eToggle;
NavigationView nav;
private LinearLayout camera, phone, dialog;
private Button attachBtn1, attachBtn2, attachBtn3, submitButton, cancel;
private TextView file1, file2, file3;
private EditText name, mail, telephone, ausgang, ziels, nachricht;
private ArrayList<Uri> attachments = new ArrayList<>();
private CheckBox agreement;
private String textfield;
public static final int REQUEST_SELECT_FILE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
initUI();
eToggle = new ActionBarDrawerToggle(this, eDrawerlayout, R.string.Open, R.string.Close);
eDrawerlayout.addDrawerListener(eToggle);
eToggle.syncState();
nav.setNavigationItemSelectedListener(this);
androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.parseColor("#f0f5f9")));
eDrawerlayout.setDrawerListener(eToggle);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
private void initUI() {
nav = findViewById(R.id.navigation1);
eDrawerlayout = findViewById(R.id.drawer1);
name = findViewById(R.id.name);
mail = findViewById(R.id.mail);
telephone = findViewById(R.id.tel);
ausgang = findViewById(R.id.aus);
ziels = findViewById(R.id.ziel);
nachricht = findViewById(R.id.nach);
submitButton = findViewById(R.id.sendBtn);
attachBtn1 = findViewById(R.id.attach_btn1);
attachBtn2 = findViewById(R.id.attach_btn2);
attachBtn3 = findViewById(R.id.attach_btn3);
/*dialog = findViewById(R.id.dialogBox);
camera = findViewById(R.id.cameraOption);
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openCamera();
}
});
phone = findViewById(R.id.phoneStorageOption);
phone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openFileChooser();
}
});
cancel = findViewById(R.id.cancelBtn);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.setVisibility(View.GONE);
}
});*/
file1 = findViewById(R.id.doc1);
file2 = findViewById(R.id.doc2);
file3 = findViewById(R.id.doc3);
attachBtn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn1";
chooseOption();
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn2";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn3";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
agreement = findViewById(R.id.checkbox);
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendData();
}
});
}
private void chooseOption() {
final CharSequence[] options = {"Camera", "Phone", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add file using: ");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Camera")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
} else if (options[item].equals("Phone")) {
openFileChooser();
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
private void openFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_SELECT_FILE);
}
private void sendData() {
if (TextUtils.isEmpty(name.getText()) || TextUtils.isEmpty(mail.getText()) ||
TextUtils.isEmpty(telephone.getText()) || TextUtils.isEmpty(ausgang.getText())
|| TextUtils.isEmpty(ziels.getText()) || TextUtils.isEmpty(nachricht.getText())
|| TextUtils.isEmpty(file1.getText()) || TextUtils.isEmpty(file3.getText()) ||
TextUtils.isEmpty(file3.getText())) {
Toast.makeText(this, "Please fill out all fields.", Toast.LENGTH_SHORT).show();
} else {
if (agreement.isChecked()) {
if (isConnected()) {
ArrayList<String> data = new ArrayList<>();
data.add(name.getText().toString());
data.add(mail.getText().toString());
data.add(telephone.getText().toString());
data.add(ausgang.getText().toString());
data.add(ziels.getText().toString());
data.add(nachricht.getText().toString());
new SendMailTask(this).execute("metaphrase.online#gmail.com", "Admintogether-2000222",
"salman.footy.k7#gmail.com", "User Information", data.get(0), data.get(1),
data.get(2), data.get(3), data.get(4), data.get(5), getFullPath(attachments.get(0)),
getFullPath(attachments.get(1)), getFullPath(attachments.get(2)));
} else {
Toast.makeText(this, "Please check your internet connection and try again.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Please select the checkbox.", Toast.LENGTH_SHORT).show();
}
}
}
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if (eToggle.onOptionsItemSelected(item)) {
}
return true;
}
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.home:
startActivity(new Intent(Auftrag.this, MainActivity.class));
break;
case R.id.web:
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("https://metaphrase.online"));
startActivity(browser);
break;
case R.id.help:
startActivity(new Intent(Auftrag.this, Feedback.class));
break;
case R.id.upload:
if (isConnected()) {
startActivity(new Intent(Auftrag.this, Auftrag.class));
} else {
Toast.makeText(this, "Bitte überprüfen Sie Ihre Internetverbindung!", Toast.LENGTH_SHORT)
.show();
}
break;
}
eDrawerlayout.closeDrawer(GravityCompat.START);
return true;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode != REQUEST_SELECT_FILE || resultCode != RESULT_OK) {
Toast.makeText(this, "No file selected.", Toast.LENGTH_SHORT).show();
dialog.setVisibility(View.GONE);
} else {
importFile(intent);
}
}
private void importFile(Intent intent) {
if (intent != null) {
String fileName = getFileName(intent.getData());
if (textfield != null) {
if (textfield.equals("btn1")) {
dialog.setVisibility(View.GONE);
file1.setText(fileName);
attachments.add(intent.getData());
} else if (textfield.equals("btn2")) {
dialog.setVisibility(View.GONE);
file2.setText(fileName);
attachments.add(intent.getData());
} else {
dialog.setVisibility(View.GONE);
file3.setText(fileName);
attachments.add(intent.getData());
}
} else {
Toast.makeText(this, "Try again later.", Toast.LENGTH_SHORT).show();
}
}
}
private String getFullPath(Uri fileUri) {
String filePath = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
try {
filePath = PathUtil.getPath(this, fileUri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
File file = new File(fileUri.getPath());
final String[] split = file.getPath().split(":");
filePath = split[1];
}
return filePath;
}
private String getFileName(Uri data) {
Cursor cursor = getContentResolver().query(data, null, null, null, null);
if (cursor.getCount() <= 0) {
cursor.close();
throw new IllegalArgumentException("Can't obtain file name, cursor is empty");
}
cursor.moveToFirst();
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
cursor.close();
return fileName;
}
public boolean isConnected() {
boolean connected = false;
try {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cm.getActiveNetworkInfo();
connected = nInfo != null && nInfo.isAvailable() && nInfo.isConnected();
return connected;
} catch (Exception e) {
Log.e("Connectivity Exception", e.getMessage());
}
return connected;
}
}
So the problem should be in the <view ../> tag, the correct form is <View ... />. You should change your XML file with the following:
<androidx.drawerlayout.widget.DrawerLayout 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:id="#+id/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>

How do I send an email with filled subject and email address?

I wrote an activity to send an email in the app. However, i can't find a way to set the recipient and subject in the edittext fill. How should I set the email at the beginning ??
my activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback_email);
emailAddress = (EditText) findViewById(R.id.email);
emailSubject = (EditText) findViewById(R.id.subject);
message = (EditText) findViewById(R.id.message);
sendEmailButton = (Button) findViewById(R.id.send_button);
sendEmailButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String toemailAddress = emailAddress.getText().toString();
String msubject = emailSubject.getText().toString();
String mmessage = message.getText().toString();
Intent emailApp = new Intent(Intent.ACTION_SEND);
emailApp.putExtra(Intent.EXTRA_EMAIL, new String[]{toemailAddress});
emailApp.putExtra(Intent.EXTRA_SUBJECT, msubject);
emailApp.putExtra(Intent.EXTRA_TEXT, mmessage);
emailApp.setType("message/rfc822");
startActivity(Intent.createChooser(emailApp, "Send Email Via"));
}
});
}
my xml file
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject"
android:textStyle="bold" />
<EditText
android:id="#+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:hint="Subject"
android:inputType="text" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView"
android:layout_marginTop="43dp"
android:text="To"
android:textStyle="bold" />
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:hint="Email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/email"
android:layout_marginTop="15dp"
android:text="Message:"
android:textStyle="bold" />
<EditText
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:gravity="top"
android:hint="Your message here..."
android:inputType="textMultiLine"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignEnd="#+id/email" />
<Button
android:id="#+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#498b24"
android:paddingTop="50dp"
android:padding="5dp"
android:text="Send Message "
android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="46dp" />
How should I set the email at the beginning ??
I am not sure if this is what you want but you can set it in the xml as android:text="example#gmail.com" For example:
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:text="example#gmail.com"
android:inputType="textEmailAddress" />

How to wrap Dialog Window to Content?

I'm developing a Dialog, which should shrink to its content, so, I want to get a behaviour like wrap_content in a common view but for a normal Dialog.
That's what I want to show in a Dialog Window
In a Dialog Window should look like this
but this is what I actually get
Could you say me what I do wrong?
I thank you in Advance.
That's my code
...
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.advanced_options);
dialog.setTitle(titleId);
// Stuff referred to builder
AlertDialog.Builder builder ...
...
int type = WindowManager.LayoutParams.TYPE_INPUT_METHOD;
WindowManager.LayoutParams w_layout_params = new WindowManager.LayoutParams(type);
dialog.getWindow().setAttributes(w_layout_params );
...
builder.create();
dialog.show();
advanced_options.xml Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relLayout_advancedOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_advanced_options"
android:divider="?android:listSeparatorTextViewStyle"
android:showDividers="" >
<TextView
android:id="#+id/speed_limit"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="#string/speed_limit"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/black"
android:textSize="14dp" />
<TextView
android:id="#+id/speed_limit_alert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/speed_limit"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="#string/speed_limit_alert"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<TextView
android:id="#+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/speed_limit_alert"
android:layout_toRightOf="#+id/speed_limit_alert_edit_text"
android:text="#string/percentage_symbol"
android:textColor="#color/black" />
<TextView
android:id="#+id/minimum_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/speed_limit_alert"
android:layout_below="#+id/speed_limit_alert_edit_text"
android:layout_marginTop="15dp"
android:text="#string/minimum_speed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<EditText
android:id="#+id/minimum_speed_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/minimum_speed"
android:layout_alignBottom="#+id/minimum_speed"
android:layout_alignLeft="#+id/speed_limit_alert_edit_text"
android:ems="3"
android:inputType="number"
android:textColor="#color/black"
android:text="6" />
<TextView
android:id="#+id/minimum_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/minimum_speed"
android:layout_alignLeft="#+id/percent"
android:text="#string/metric_speed_unit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<TextView
android:id="#+id/maximum_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/minimum_speed"
android:layout_below="#+id/minimum_speed_edit_text"
android:layout_marginTop="15dp"
android:text="#string/maximum_speed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black"/>
<EditText
android:id="#+id/maximum_speed_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/maximum_speed"
android:layout_alignBottom="#+id/maximum_speed"
android:layout_alignLeft="#+id/minimum_speed_edit_text"
android:ems="3"
android:inputType="number"
android:textColor="#color/black"
android:text="18" />
<TextView
android:id="#+id/maximum_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/maximum_speed"
android:layout_toRightOf="#+id/maximum_speed_edit_text"
android:text="#string/metric_speed_unit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black"/>
<TextView
android:id="#+id/mobile_device_performance"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/maximum_speed_edit_text"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:text="#string/mobile_device_performance"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/black"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/maximum_number_objects"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/maximum_speed"
android:layout_below="#+id/mobile_device_performance"
android:layout_marginTop="20dp"
android:text="#string/maximum_objects_in_view"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<EditText
android:id="#+id/maximum_number_objects_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/maximum_number_objects"
android:layout_alignBottom="#+id/maximum_number_objects"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/maximum_number_objects"
android:ems="3"
android:inputType="number"
android:text="450"
android:textColor="#color/black" />
<EditText
android:id="#+id/speed_limit_alert_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/percent"
android:layout_alignBottom="#+id/percent"
android:layout_alignLeft="#+id/maximum_number_objects_edit_text"
android:ems="3"
android:inputType="number"
android:text="42"
android:textColor="#color/black" >
<requestFocus />
</EditText>
<View
android:id="#+id/void_view"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/maximum_speed_unit"
android:layout_below="#+id/maximum_number_objects" />
Change RelativeView's width to match_parent
What you're looking for is match_parent's behavior.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relLayout_advancedOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_advanced_options"
android:divider="?android:listSeparatorTextViewStyle"
android:showDividers="" >
Note: wrap_content in android specifies the view to use as little space as needed and that is the behavior you're getting.
I could adjust the Dialog (NOT AlertDialog!) to my custom Layout but I couldn't* set either the Title or the Buttons so that I got an Exception cause of setting content before requestFeature, then I decided to custom my Dialog and including the Buttons and title in my Custom Layout.
*I have researched and it's possible to overcome that if we define the Dialog in OnCreate other even in OnCreateDialog but I have an extra Class just for static Dialog Methods and was no solution for me.
In Addition I post what it was useful for me, perhaps someone is also useful.
Now my custom dialog looks like this
Here the code for whom wants to test it.
/**
* #param c
* the Context
* #return the about dialog
*/
public static void getAdvancedOptions(final Activity activity) {
Log.i("TAG", "Dialogs::getAdvancedOptions:: 0");
//settings = session.getSettings();
// Creation of a Dialog with Frame and title Characteristics
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.advanced_options_expanded);
// Here we control the validity of "edit_text" Fields
speed_limit_alert = (EditText)dialog.findViewById(R.id.speed_limit_alert_edit_text);
minimum_speed = (EditText)dialog.findViewById(R.id.minimum_speed_edit_text);
maximum_speed = (EditText)dialog.findViewById(R.id.maximum_speed_edit_text);
max_objects_in_view = (EditText)dialog.findViewById(R.id.maximum_number_objects_edit_text);
//showAdvancedOptions("getAdvancedOptions 1::");
// First we set the "SharedPreferences"-saved values on EditText Fields
performEditText(speed_limit_alert,Constants.MIN_PERCENTAGE, Constants.MAX_PERCENTAGE,"speed_limit_alert");
performEditText(minimum_speed, "","", "minimum_speed");
performEditText(maximum_speed, "","","maximum_speed");
performEditText(max_objects_in_view, "","","max_objects_in_view");
//showAdvancedOptions("getAdvancedOptions 4::");
ok_button = (Button)dialog.findViewById(R.id.ok_button);
cancel_button = (Button)dialog.findViewById(R.id.cancel_button);
// Definition of "OK" Button for the Dialog
ok_button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Log.i("TAG", "Dialogs::getAdvancedOptions::onClick");
if ( dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
});
cancel_button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Log.i("TAG", "Dialogs::getAdvancedOptions::onClick");
if ( dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
});
dialog.show();
}
private static void performEditText(EditText edit_text, final String min_value, final String max_value, final String id) {
String edit_text_value = edit_text.getText().toString();
Log.i("TAG", "Dialogs::performEditText:: id: "+ id +" edit_text_value: "+edit_text_value+ " (min_value,max_value)=("+min_value+","+max_value+")");
TextWatcher textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
int i = 0;
Log.i("TAG","Dialogs::performEditText::afterTextChanged:id: "+ id +" - 0 : s: "+s.toString());
int length = s.length();
if ( length == 0 )
i = 0;
else if ( length < 3 ) {
if ( s.charAt(0) == '0')
s.delete(1, length );
i = Integer.parseInt(s.toString());
Log.i("TAG","Dialogs::performEditText::afterTextChanged:id: "+ id +" - 1a : s: "+s+", i:"+i);
} else {
//String hundred = "100";
String s_value = s.toString();
Log.i("TAG","Dialogs::performEditText::afterTextChanged: id: "+ id +" - 1b : s: "+s+", i:"+i);
if ( ( min_value != null ) && ( min_value.length() != 0 ) && ( max_value != null) && ( max_value.length() != 0 )) {
if ( !s_value.equalsIgnoreCase(max_value))
s.delete(2, length );
}
i = Integer.parseInt(s.toString());
Log.i("TAG","Dialogs::performEditText::afterTextChanged: id: "+ id +" - 2b : i: "+i);
}
if (i >= 0 && i <= 100) {
Log.i("TAG","Dialogs::performEditText::afterTextChanged: id: "+ id +" - 3 : (i >= 0 && i <= 100): i: "+i);
//speed_limit_alert.setText(s); // This ensures 0-100 value for speed_limit_alert
}
Log.i("TAG","Dialogs::performEditText::afterTextChanged: id: "+ id +" - 4 : i: "+i);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.i("TAG","Dialogs::performEditText::beforeTextChanged: id: "+ id +" s: "+s);
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.i("TAG","Dialogs::performEditText::onTextChanged: id: "+ id +" s: "+s);
}
};
edit_text.addTextChangedListener(textWatcher);
}
private static void showAdvancedOptions(String entryPoint) {
String s_l_a = speed_limit_alert.getText().toString();
Log.i("TAG", entryPoint + "Dialogs::setAdvancedOptions:: s_l_a: "+s_l_a);
String mi_s = minimum_speed.getText().toString();
Log.i("TAG", entryPoint + "Dialogs::setAdvancedOptions:: mi_s: "+mi_s);
String ma_s = maximum_speed.getText().toString();
Log.i("TAG", entryPoint + "Dialogs::setAdvancedOptions:: ma_s: "+ma_s);
String m_o_i_v = max_objects_in_view.getText().toString();
Log.i("TAG", entryPoint + "Dialogs::setAdvancedOptions:: m_o_i_v: "+m_o_i_v);
}
And the layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/border_advanced_options"
android:divider="?android:listSeparatorTextViewStyle"
android:showDividers="middle" >
<RelativeLayout
android:id="#+id/relLayout_advancedOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:divider="?android:listSeparatorTextViewStyle"
android:orientation="vertical"
android:showDividers="" >
<TextView
android:id="#+id/speed_limit"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/void_view_0"
android:layout_marginTop="10dp"
android:text="#string/speed_limit"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/black"
android:textSize="14dp" />
<TextView
android:id="#+id/speed_limit_alert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/speed_limit"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="#string/speed_limit_alert"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<TextView
android:id="#+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/speed_limit_alert"
android:layout_toRightOf="#+id/speed_limit_alert_edit_text"
android:text="#string/percentage_symbol"
android:textColor="#color/black" />
<TextView
android:id="#+id/minimum_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/speed_limit_alert"
android:layout_below="#+id/speed_limit_alert_edit_text"
android:layout_marginTop="15dp"
android:text="#string/minimum_speed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<EditText
android:id="#+id/minimum_speed_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/minimum_speed"
android:layout_alignBottom="#+id/minimum_speed"
android:layout_alignLeft="#+id/speed_limit_alert_edit_text"
android:ems="3"
android:inputType="number"
android:text="6"
android:textColor="#color/black" />
<TextView
android:id="#+id/minimum_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/minimum_speed"
android:layout_alignLeft="#+id/percent"
android:paddingRight="5dp"
android:text="#string/metric_speed_unit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<TextView
android:id="#+id/maximum_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/minimum_speed"
android:layout_below="#+id/minimum_speed_edit_text"
android:layout_marginTop="15dp"
android:text="#string/maximum_speed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<EditText
android:id="#+id/maximum_speed_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/maximum_speed"
android:layout_alignBottom="#+id/maximum_speed"
android:layout_alignLeft="#+id/minimum_speed_edit_text"
android:ems="3"
android:inputType="number"
android:text="18"
android:textColor="#color/black" />
<TextView
android:id="#+id/maximum_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/maximum_speed"
android:layout_alignRight="#+id/minimum_speed_unit"
android:layout_toRightOf="#+id/maximum_speed_edit_text"
android:paddingRight="5dp"
android:text="#string/metric_speed_unit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<TextView
android:id="#+id/mobile_device_performance"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/maximum_speed_edit_text"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:text="#string/mobile_device_performance"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/black"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="#+id/maximum_number_objects"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/maximum_speed"
android:layout_below="#+id/mobile_device_performance"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="#string/maximum_objects_in_view"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/black" />
<EditText
android:id="#+id/maximum_number_objects_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/maximum_number_objects"
android:layout_alignBottom="#+id/maximum_number_objects"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/maximum_number_objects"
android:ems="3"
android:inputType="number"
android:text="450"
android:textColor="#color/black" />
<EditText
android:id="#+id/speed_limit_alert_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/percent"
android:layout_alignBottom="#+id/percent"
android:layout_alignLeft="#+id/maximum_number_objects_edit_text"
android:digits="0123456789"
android:ems="3"
android:inputType="number"
android:text="42"
android:textColor="#color/black" >
<requestFocus />
</EditText>
<View
android:id="#+id/void_view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/lin_layout_buttons"
android:layout_below="#+id/maximum_number_objects"
android:background="#color/black" />
<TextView
android:id="#+id/title_advanced_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/minimum_speed_unit"
android:drawableLeft="#drawable/ic_launcher_48"
android:drawableRight="#drawable/ic_action_settings_48"
android:gravity="center|center_vertical"
android:paddingLeft="5dp"
android:text="Advanced Options"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/blue" />
<View
android:id="#+id/void_view_0"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/title_advanced_options"
android:layout_below="#+id/title_advanced_options"
android:background="#color/black" />
<LinearLayout
android:id="#+id/lin_layout_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/minimum_speed_unit"
android:layout_alignTop="#+id/void_view"
android:weightSum="3" >
<Button
android:id="#+id/ok_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/maximum_number_objects"
android:layout_alignRight="#+id/speed_limit_alert"
android:layout_below="#+id/maximum_number_objects_edit_text"
android:layout_weight="1.5"
android:text="OK" />
<Button
android:id="#+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:layout_weight="1.5"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>

Categories

Resources