Issue
I'm working on mobile application, Java Android and I'm using Android Studio as IDE.
On the first screen (first Activity) there is no problems and the button to go to the second Activity is working well.
But I have 3 activities and I've put a button in the second Activity (to switch to the third Activity). This button is visible on design, but invisible when I run the application with Emulator. I can't understand why. Could somebody help me?
This is java file
package com.example.debit_cablage.controler;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.debit_cablage.R;
public class EditorActivity extends AppCompatActivity {
public static final String ACTION ="com.example.SHOW_REPORT_ACTIVITY";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setPadding(16, 16, 16, 16);
Bundle arguments = getIntent().getExtras();
if(arguments != null) {
String name = arguments.get("spinner_name").toString();
String affaire = arguments.get("spinner_affaire").toString();
String equipe = arguments.get("spinner_equipe").toString();
textView.setText("Vous êtes : " + name + "\nVous prenez les matériels pour le numéro d'affiare : " + affaire + "\net pour l'équipement : "+ equipe);
}
setContentView(textView);
}
public void onClickEditor(View view) {
Intent intent2 = new Intent(this, ReportActivity.class);
startActivity(intent2);
}
}
And this is XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.example.debit_cablage.controler.EditorActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textSize="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.06" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="161dp"
android:background="@android:color/holo_blue_light"
android:onClick="onClickEditor"
android:text="Continuer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">
</Button>
</android.support.constraint.ConstraintLayout>
Solution
As said in the comments, you just have to remove the 2nd setContentView()
But if you want to display the retrieved information, you can use the TextView
defined in the xml layout
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
TextView textView = (TextView)findViewById(R.id.textView2);
Bundle arguments = getIntent().getExtras();
if(arguments != null) {
String name = arguments.get("spinner_name").toString();
String affaire = arguments.get("spinner_affaire").toString();
String equipe = arguments.get("spinner_equipe").toString();
textView.setText("Vous êtes : " + name + "\nVous prenez les matériels pour le numéro d'affiare : " + affaire + "\net pour l'équipement : "+ equipe);
}
}
Answered By - Bruno
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.