Help Me Please to find the error
Please when i click the button my application close
emp.XML
**XML file*
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/lawa"
tools:context="com.example.johnwalls.projet.Main2Activity">
<EditText
android:id="#+id/username"
android:layout_width="150dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="textPersonName"
android:textSize="10dp"
android:background="#ffffffff"
android:textColor="#000"
android:textColorHighlight="#ffffffff"
android:phoneNumber="false"
android:text=""
style="#android:style/TextAppearance.Large"
android:textStyle="bold"
android:typeface="sans"
android:layout_marginBottom="90dp"
android:layout_alignBottom="#+id/pass"
android:layout_alignLeft="#+id/pass"
android:layout_alignStart="#+id/pass" />
android:text="" />
<EditText
android:id="#+id/pass"
android:layout_width="150dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="textPassword"
android:textSize="10dp"
android:background="#ffffffff"
android:textColor="#000"
android:textColorHighlight="#ffffffff"
android:phoneNumber="false"
android:text=""
style="#android:style/TextAppearance.Large"
android:textStyle="bold"
android:typeface="sans"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/log"
android:layout_alignStart="#+id/log" />
<Button
android:text=""
android:layout_width="105.0dp"
android:layout_height="40.0dp"
android:id="#+id/log"
android:background="#drawable/log"
android:layout_marginLeft="10dp"
android:layout_marginTop="340dp"
android:textAllCaps="false"
android:onClick=""
/>
<Button
android:text=""
android:layout_width="105.0dp"
android:layout_height="40.0dp"
android:background="#drawable/ins"
android:layout_marginLeft="120dp"
android:layout_marginTop="340dp"
android:textAllCaps="false"
android:onClick="goButtonClicked"
android:id="#+id/goButton"
/>
</RelativeLayout>`
Main2Activity.java
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emp);
}
public void goButtonClicked(View v) {
Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
startActivity(i);
}
}
SaveadminActivity
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SaveadminActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.enregistreradmin);
}
}
[enter image description here][1]
What are you trying to achieve
what are you expecting to get out
What did you get out (include error messages)
What else have you tried?
What do you think is causing it?
Why do you need to make a new question for it? Why is your problem different to other, similar questions on here?
This is how you can solve the issue
emp.XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/lawa"
tools:context="com.example.johnwalls.projet.Main2Activity">
<EditText
android:id="#+id/username"
android:layout_width="150dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="textPersonName"
android:textSize="10dp"
android:background="#ffffffff"
android:textColor="#000"
android:textColorHighlight="#ffffffff"
android:phoneNumber="false"
android:text=""
style="#android:style/TextAppearance.Large"
android:textStyle="bold"
android:typeface="sans"
android:layout_marginBottom="90dp"
android:layout_alignBottom="#+id/pass"
android:layout_alignLeft="#+id/pass"
android:layout_alignStart="#+id/pass" />
android:text="" />
<EditText
android:id="#+id/pass"
android:layout_width="150dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="textPassword"
android:textSize="10dp"
android:background="#ffffffff"
android:textColor="#000"
android:textColorHighlight="#ffffffff"
android:phoneNumber="false"
android:text=""
style="#android:style/TextAppearance.Large"
android:textStyle="bold"
android:typeface="sans"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/log"
android:layout_alignStart="#+id/log" />
<Button
android:text=""
android:layout_width="105.0dp"
android:layout_height="40.0dp"
android:id="#+id/log"
android:background="#drawable/log"
android:layout_marginLeft="10dp"
android:layout_marginTop="340dp"
android:textAllCaps="false"
/>
<Button
android:text=""
android:layout_width="105.0dp"
android:layout_height="40.0dp"
android:background="#drawable/ins"
android:layout_marginLeft="120dp"
android:layout_marginTop="340dp"
android:textAllCaps="false"
android:id="#+id/goButton"
/>
</RelativeLayout>
Main2Activity.java
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Main2Activity extends AppCompatActivity {
Button goButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emp);
goButton=(Button)findViewById(R.id.goButton);
goButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
startActivity(i);
}
});
}
}
In Main2Activity delete goButton method and add to onCreate this
goButton=(Button)findViewById(R.id.goButton);
goButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
startActivity(i);
}
});
Main2Activity will looks like this
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class Main2Activity extends AppCompatActivity {
Button goButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emp);
goButton=(Button)findViewById(R.id.goButton);
goButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(Main2Activity.this,SaveadminActivity.class);
startActivity(i);
}
});
}
Related
knowing that there is no errors, only MainActivity shows without homebutton................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
MainActivity.java
package com.example.AppCalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText etfirstvalue,etsecondvalue;
Button btnadd,btnsubs,btnmultiply,btndivide;
Double num1,num2;
TextView tvresult;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etfirstvalue=findViewById(R.id.etfirstvalue);
etsecondvalue=findViewById(R.id.etsecondvalue);
btnadd=findViewById(R.id.btnadd);
btndivide=findViewById(R.id.btndivision);
btnmultiply=findViewById(R.id.btnmultiply);
btnsubs=findViewById(R.id.btnsubs);
tvresult=findViewById(R.id.tvresult);
Clicklistener();
}
public void Clicklistener(){
btnadd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
num1=Double.parseDouble(etfirstvalue.getText().toString());
num2=Double.parseDouble(etsecondvalue.getText().toString());
Double result=num1+num2;
tvresult.setText(String.valueOf(result));
}
});
btnsubs.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
num1=Double.parseDouble(etfirstvalue.getText().toString());
num2=Double.parseDouble(etsecondvalue.getText().toString());
Double result=num1-num2;
tvresult.setText(String.valueOf(result));
}
});
btnmultiply.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
num1=Double.parseDouble(etfirstvalue.getText().toString());
num2=Double.parseDouble(etsecondvalue.getText().toString());
Double result=num1*num2;
tvresult.setText(String.valueOf(result));
}
});
btndivide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
num1=Double.parseDouble(etfirstvalue.getText().toString());
num2=Double.parseDouble(etsecondvalue.getText().toString());
Double result=num1/num2;
tvresult.setText(String.valueOf(result));
}
});
}
}
MainActivity.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:background="#FFFFFF"
android:backgroundTint="#FFFFFF"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="Simple Calculator"
android:textSize="25sp" />
<EditText
android:id="#+id/etfirstvalue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter First Value"
android:inputType="number" />
<EditText
android:id="#+id/etsecondvalue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Second Value"
android:inputType="number" />
<TextView
android:id="#+id/tvresult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="Result"
android:textColor="#color/purple_500"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginHorizontal="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btnadd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="1"
android:backgroundTint="#color/purple_500"
android:text="ADD" />
<Button
android:id="#+id/btnsubs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="1"
android:backgroundTint="#color/purple_500"
android:text="Subs" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginHorizontal="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btnmultiply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="1"
android:backgroundTint="#color/purple_500"
android:text="Multiply" />
<Button
android:id="#+id/btndivision"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="1"
android:backgroundTint="#color/purple_500"
android:text="Divide" />
</LinearLayout>
</LinearLayout>
homebutton.java
package com.example.AppCalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class homebutton extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homebutton);
Button btncalc=findViewById(R.id.btncalc);
btncalc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(homebutton.this, MainActivity.class);
startActivity(intent);
}
});
}
}
homebutton.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"
tools:context=".homebutton"
tools:ignore="ExtraText">
<Button
android:id="#+id/btncalc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_weight="1"
android:backgroundTint="#color/purple_500"
android:text="Calculator" />
</LinearLayout>
You need to clarify your question more. However I believe you meant homebutton should start first and after you click calculate it should take you to the second one.
If that's the case, then you need to define your start activity from the AndroidManifest because currently your app is starting on MainActivity.java
I am creating my first app which is when I press a button I simply move to the next page, but every time I press the button my app crashes (Ignore the username and password texts they don't do anything yet). I am trying to move from login to home page.
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/gradient"
tools:context=".Login">
<ImageView
android:id="#+id/imageView"
android:layout_width="120dp"
android:layout_height="150dp"
android:layout_marginTop="59dp"
app:srcCompat="#drawable/logo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/username"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:background="#11000000"
android:drawableLeft="#drawable/ic_action_user"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:textSize="16dp" />
<EditText
android:id="#+id/password"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_below="#id/username"
android:layout_alignStart="#id/username"
android:layout_alignLeft="#id/username"
android:layout_marginTop="38dp"
android:background="#11000000"
android:drawableLeft="#drawable/ic_action_pass"
android:ems="10"
android:hint="Password"
android:inputType="textPersonName"
android:textSize="16sp" />
<Button
android:id="#+id/login"
android:layout_width="321dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="207dp"
android:background="#color/colorAccent"
android:onClick="loginButton"
android:text="Login" />
<TextView
android:id="#+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="139dp"
android:text="Register Here"
android:textColor="#fff"
android:textSize="14sp" />
<TextView
android:id="#+id/attempts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="74dp"
android:text="Incorrect Attempts: "
android:textColor="#fff"
android:textSize="14sp" />
</RelativeLayout>
Login.java
package com.example.chorehelpers;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
public class Login extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void onClick (View v){
switch (v.getId()){
case R.id.login:
loginButton(v);
break;
}
}
public void loginButton(View v) {
Intent i = new Intent (Login.this, HomePage.class);
startActivity(i);
}
}
activity_home_page.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#drawable/gradient"
tools:context=".HomePage">
</RelativeLayout>
HomePage.java
package com.example.chorehelpers;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class HomePage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
}
}
Please Help.
why are u using this method
public void onClick (View v){
switch (v.getId()){
case R.id.login:
loginButton(v);
break;
}
remove it and rerun the app , Hope it woks
**Please try to update Login.java class like this,**
package com.example.chorehelpers;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
public class Login extends AppCompatActivity {
private Button loginButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginButton = (Button) findViewById(R.id.login);
loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent x = new Intent(LoginActivity.this, HomePageActivity.class);
startActivity(x);
}
});
}
}
I'm trying to find out how to set a string that will be read out-loud.
For example:
String text = "Hello";
You can find a very detail example that show how to convert text to speech on this site. HTH.
Your MainActivity.java should look something like this
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
public class MainActivity extends Activity {
TextToSpeech t1;
EditText ed1;
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
b1=(Button)findViewById(R.id.button);
t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String toSpeak = ed1.getText().toString();
Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
public void onPause(){
if(t1 !=null){
t1.stop();
t1.shutdown();
}
super.onPause();
}
}
And here is the content of activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:transitionGroup="true">
<TextView android:text="Text to Speech" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="#+id/textView"
android:layout_below="#+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/abc"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:theme="#style/Base.TextAppearance.AppCompat" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_below="#+id/imageView"
android:layout_marginTop="46dp"
android:hint="Enter Text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff7aff10"
android:textColorHint="#ffff23d1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text to Speech"
android:id="#+id/button"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp" />
</RelativeLayout>
MainActivity.Java
package com.example.drexsprint.login;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Button b1,b2;
EditText ed1,ed2;
TextView tx1;
int counter = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
ed1=(EditText)findViewById(R.id.editText);
ed2=(EditText)findViewById(R.id.editText2);
b2=(Button)findViewById(R.id.button2);
tx1=(TextView)findViewById(R.id.textView3);
tx1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(ed1.getText().toString().equals("admin") &&
ed2.getText().toString().equals("1234")) {
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "Wrong Credentials",Toast.LENGTH_SHORT).show();
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED);
counter--;
tx1.setText(Integer.toString(counter));
if (counter == 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Arduino Security"
android:id="#+id/textView"
android:textColor="#ff7aff24"
android:textSize="35dp"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:hint="Enter Name"
android:focusable="true"
android:textColorHighlight="#ff7eff15"
android:textColorHint="#ffff25e6"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText2"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText"
android:textColorHint="#ffff299f"
android:hint="Password" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="#+id/textView2"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView3"
android:layout_alignTop="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/textView2"
android:textSize="25dp"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
android:id="#+id/button"
android:layout_alignParentBottom="true"
android:textColor="#ddec0d"
android:background="#0e17c2"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="#+id/button2"
android:layout_alignParentBottom="true"
android:background="#df0c0c"
android:textColor="#0dca07"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:layout_centerHorizontal="true" />
<TextView
android:text="Please Login:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:textSize="35dp"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>
Second Screen App
screen.Java
package com.example.drexsprint.login;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Screen extends AppCompatActivity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
}
public void Left(View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/?button2");
}
public void Right (View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/?button3");
}
public void Temp (View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/?button1");
}
public void Hum (View view) {
myWebView.loadUrl("http://admin:0000000AA#10.0.1.16/button1");
}
public void Photo (View view) {
goToUrl("http://admin:0000000AA#10.0.1.6/image.jpg");
}
private void goToUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
/** public void Photo (View view) {
// myWebView.loadUrl("http://admin:0000000AA#10.0.1.6/image.jpg");
}**/
}}
screen_layout
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/webView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="invisible"
android:layout_above="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate Left"
android:id="#+id/button"
android:onClick="Left"
android:backgroundTint="#0f50e8"
android:textColor="#f4d318"
android:layout_above="#+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/button5"
android:layout_alignRight="#+id/button4"
android:layout_alignEnd="#+id/button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate Right"
android:id="#+id/button2"
android:onClick="Right"
android:backgroundTint="#0f50e8"
android:textColor="#f4d318"
android:layout_below="#+id/webView"
android:layout_alignRight="#+id/webView"
android:layout_alignEnd="#+id/webView"
android:layout_alignLeft="#+id/button3"
android:layout_alignStart="#+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Temp."
android:id="#+id/button3"
android:onClick="Temp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:backgroundTint="#369d7c"
android:textColor="#f4d318" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Hum."
android:id="#+id/button4"
android:onClick="Hum"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:backgroundTint="#369d7c"
android:textColor="#f4d318" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Photo"
android:id="#+id/button5"
android:onClick="Photo"
android:backgroundTint="#589d36"
android:textColor="#f4d318"
android:layout_below="#+id/webView"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/videoView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/webView"
android:background="#0a0a0a"
android:clickable="true"
android:contextClickable="true"
android:focusable="true" />
</RelativeLayout>
Okay! So I got two aplications, the first one is a login screen and the second one is a main menu of what the application should do, I want to find a way so that when a user insert the correct credentials and click on the Login button the app executes the second screen the main menu, how can i do this, Join the two apps together.
Wat i wanna achieve is on the the click of "Login Button" on the first app it Launches the Second app as a window! Thanks!! Kind of new in android any detailed help would be much appreciated.
Use startActivityForResult() to get the result from another activity.
By the help of android startActivityForResult() method, we can send information from one activity to another and vice-versa.
Intent intent=new Intent(this,Class2.class);
startActivityForResult(intent,10);
main activity.java
package abhilmohan.blogspot.com;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
EditText amount1;
EditText amount2;
EditText amount3;
EditText amount4;
Button calculate;
double w=0;
double x=0;
double y=0;
double z=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
public void initcontrols() {
amount1=(EditText)findViewById(R.id.editText1);
amount2=(EditText)findViewById(R.id.editText2);
amount3=(EditText)findViewById(R.id.editText3);
amount4=(EditText)findViewById(R.id.editText4);
calculate=(Button)findViewById(R.id.button1);
}
public void calculate() {
w=Double.parseDouble(amount1.getText().toString());
x=Double.parseDouble(amount2.getText().toString());
y=w/12;
amount3.setText(Double.toString(y));
z=w*x/100;
amount4.setText(Double.toString(z));
}
public void gotoactivity (View v) {
Intent intent = new Intent(this,ResultPage.class);
calculate();
startActivity(intent);
}
am not getting result while calling calculator() void method on button click.i want my results to be published in two textviews created in reulst_page layout
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="left"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="abhilmohan.blogspot.com.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/ctc"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:inputType="number"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/TDS"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:inputType="number"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/ok"
android:textColor="#ffffff"
android:onClick="gotoactivity" />
</LinearLayout>
</RelativeLayout>
resultpage.java
package abhilmohan.blogspot.com;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.app.ActionBar;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class ResultPage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_page);
getActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()== android.R.id.home)
{
finish();
}
return super.onOptionsItemSelected(item);
}
}
result_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/tdsamount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/rate"
android:textColor="#ffffff" />
</LinearLayout>
At the moment you are executing calculate() in the MainActivity.java second activity called ResultPage doesn't exist, therefore you can't change it's view (editText3and editText4).
In order to pass data to another activity you should fill your Intent with some extra data and then in your ResultPage activity's onCreate you would get underlying extras.
EDIT
MainActivity.java
public void gotoactivity (View v) {
calculate();
Intent intent = new Intent(this, ResultPage.class);
intent.putExtra("AMOUNT_3", y);
intent.putExtra("AMOUNT_4", z);
startActivity(intent);
}
ResultPage.java inside onCreate
Bundle extras = getIntent().getExtras();
if (extras != null) {
int amount3 = extras.getInt("AMOUNT_3");
int amount4 = extras.getInt("AMOUNT_4");
}