ConstraintLayout braking after displaying Android Studio - java

I am currently working on an android app, and I'm having an issue with displaying XML layout
In Android Studio, everything looks fine, but in the VM it doesn't look too good.
This is how it looks in Android Studio:
And here is how it looks like when it's displayed in VM:
I should probably mention that it is supposed to be a pop up window
Here is XML code:
<androidx.constraintlayout.widget.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="350dp"
android:layout_height="265dp"
android:background="#drawable/rounded_corners_grey"
android:padding="20dp"
>
<android.widget.Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Cancel"
android:background="#android:color/transparent"
android:textColor="#color/white"
android:outlineProvider="none"
app:layout_constraintTop_toBottomOf="#+id/TimerValluesBackground"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="48dp"
android:layout_marginStart="56dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.0" />
<android.widget.Button
android:text="Set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SaveTimer"
android:background="#drawable/rounded_corners_dark"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/Cancel"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="56dp"
app:layout_constraintTop_toTopOf="#+id/Cancel"
app:layout_constraintVertical_bias="0.0" />
<View
android:layout_width="300dp"
android:layout_height="100dp"
android:id="#+id/TimerValluesBackground"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="24dp"
android:clickable="false"
android:background="#drawable/rounded_corners_dark"
tools:ignore="MissingConstraints"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.32" />
<TextView
android:text="0 h"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/hourValue"
android:textSize="22dp"
android:textColor="#fff"
app:layout_constraintTop_toTopOf="#+id/TimerValluesBackground"
app:layout_constraintStart_toStartOf="#+id/TimerValluesBackground"
app:layout_constraintBottom_toBottomOf="#+id/TimerValluesBackground"
android:layout_marginStart="32dp"
app:layout_constraintVertical_bias="0.514" />
<TextView
android:text="0 min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/minuteValue"
android:textSize="22dp"
android:textColor="#fff"
app:layout_constraintTop_toTopOf="#+id/TimerValluesBackground"
app:layout_constraintStart_toEndOf="#+id/hourValue"
app:layout_constraintEnd_toStartOf="#+id/secondValue"
app:layout_constraintBottom_toBottomOf="#+id/TimerValluesBackground" />
<TextView
android:text="0 sec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/secondValue"
android:textSize="22dp"
android:textColor="#fff"
tools:layout_editor_absoluteX="231dp"
app:layout_constraintTop_toTopOf="#+id/TimerValluesBackground"
app:layout_constraintBottom_toBottomOf="#+id/TimerValluesBackground"
tools:ignore="MissingConstraints"
app:layout_constraintVertical_bias="0.514" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is code from the Main Activity:
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.TransitionDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
public class MainActivity extends AppCompatActivity {
private String ipAddress = "192.168.1.59";
private int port = 2000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Setting background color
View view = this.getWindow().getDecorView();
view.setBackgroundColor(Color.rgb(30,30,30));
// hiding bottom navigation bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
// Initiation request
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"volume").execute();
// Click event for Volume Up button
ImageButton VolumeUp = (ImageButton) findViewById(R.id.VolumeUpButton);
VolumeUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"volume up").execute();
}
});
// Click event for Volume Down button
ImageButton VolumeDown = (ImageButton) findViewById(R.id.VolumeDownButton);
VolumeDown.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"volume down").execute();
}
});
// Click event for Volume Up Lot button (lot means volume does up for about 33 %)
ImageButton VolumeUpLot = (ImageButton) findViewById(R.id.VolumeUpLotButton);
VolumeUpLot.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"volume up lot").execute();
}
});
// Click event for Volume Down Lot button (lot means volume does down for about 33 %)
ImageButton VolumeDownLot = (ImageButton) findViewById(R.id.VolumeDownLotButton);
VolumeDownLot.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"volume down lot").execute();
}
});
// Click event for ScreenShot Button
ImageView ScreenShotButton = (ImageView) findViewById(R.id.ScreenShotButton);
ScreenShotButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"screenshot").execute();
}
});
// Click event for Lock Button
ImageView LockScreenButton = (ImageView) findViewById(R.id.LockScreenButton);
LockScreenButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"lock").execute();
}
});
// Click event for Mute Button
ImageView MuteButton = (ImageView) findViewById(R.id.MuteButton);
MuteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"mute").execute();
}
});
// Enter press event for ippAddress input
EditText ipAddressInput = (EditText) findViewById(R.id.ipAddress);
ipAddressInput.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
ipAddress = ipAddressInput.getText().toString();
Log.i("Ip Address changed", String.valueOf(ipAddress));
return true;
}
return false;
}
});
// Enter press event for port input
EditText portInput = (EditText) findViewById(R.id.port);
portInput.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
port = Integer.parseInt(portInput.getText().toString());
Log.i("Port changed", String.valueOf(port));
return true;
}
return false;
}
});
// Click event for Shutdown scheduler
ImageView shutdownScheduler = (ImageView) findViewById(R.id.ShutdownTimer);
View parent = (View) findViewById(R.id.ParentViewFroPopUp);
parent.setClickable(false);
//Overlay animation init
///TransitionDrawable transition = (TransitionDrawable) parent.getBackground();
shutdownScheduler.setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View v) {
// treba dorobit to dialogove okno a tam mat nastavenia a vlastne tlacidlo na zrusenie timeru
//int time = 2000;
//new ConnectionWithServer((Activity) MainActivity.this,MainActivity.this,ipAddress,port,"timer " + time).execute();
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup,null );
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setOverlapAnchor(true);
Button btnDismiss = (Button)popupView.findViewById(R.id.Cancel);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
parent.setBackgroundColor(Color.parseColor("#00000000"));
//transition.reverseTransition(5000);
}});
//transition.startTransition(5000);
popupWindow.showAtLocation(parent, Gravity.CENTER,0, 0);
parent.setBackgroundColor(Color.parseColor("#90000000"));
}});
}
}

Try adding,
app:layout_constraintEnd_toEndOf="#+id/TimerValluesBackground"
to your last TextView(#+id/secondValue) component.

In your implementation you have forgotten to add some contraints to your views.
In order that they are display as you would like, try to add all four constraints when possible.
<androidx.constraintlayout.widget.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"
android:background="#color/quantum_black_100"
android:padding="20dp">
<android.widget.Button
android:id="#+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="48dp"
android:background="#android:color/transparent"
android:outlineProvider="none"
android:text="Cancel"
android:textColor="#color/places_text_white_alpha_26"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/SaveTimer"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/TimerValluesBackground" />
<android.widget.Button
android:id="#+id/SaveTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="56dp"
android:text="Set"
android:textColor="#color/quantum_white_100"
app:layout_constraintBottom_toBottomOf="#+id/Cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/Cancel"
app:layout_constraintTop_toTopOf="#+id/Cancel" />
<View
android:id="#+id/TimerValluesBackground"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_marginTop="24dp"
android:clickable="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/hourValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 h"
android:textColor="#fff"
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="#+id/TimerValluesBackground"
app:layout_constraintEnd_toStartOf="#+id/minuteValue"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/TimerValluesBackground"
app:layout_constraintStart_toStartOf="#+id/TimerValluesBackground"
app:layout_constraintTop_toTopOf="#+id/TimerValluesBackground" />
<TextView
android:id="#+id/minuteValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 min"
android:textColor="#fff"
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="#+id/TimerValluesBackground"
app:layout_constraintEnd_toStartOf="#+id/secondValue"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/hourValue"
app:layout_constraintTop_toTopOf="#+id/TimerValluesBackground" />
<TextView
android:id="#+id/secondValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 sec"
android:textColor="#fff"
android:textSize="22dp"
app:layout_constraintBottom_toBottomOf="#+id/TimerValluesBackground"
app:layout_constraintEnd_toEndOf="#+id/TimerValluesBackground"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/minuteValue"
app:layout_constraintTop_toTopOf="#+id/TimerValluesBackground"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

Related

Intent/Start activity starting the wrong activity?

For some reason, my start activity sends me to the wrong activity( sending me to add task class vs review task class) no error and following in log cat doesn't help me track down the issue. I tried using startActivityForResult(); but that did not help at all and had the same issue. It goes to createTask.class. I need to put more details but I am not sure what else to put, Maybe the put extra and putting two items packed to the instance, but I don't think that would be an issue
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<TextView
android:id="#+id/amountOfTasksTextViewUIMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You Have 0 Tasks"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.14"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.04000002" />
<Button
android:id="#+id/viewTaskButtonUIMain"
android:layout_width="209dp"
android:layout_height="46dp"
android:text="#string/viewTaskButtonUIMainString"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26999998" />
<Button
android:id="#+id/createTaskButtonUIMain"
android:layout_width="209dp"
android:layout_height="46dp"
android:text="#string/createTaskButtonUIMainString"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/viewTaskButtonUIMain"
app:layout_constraintStart_toStartOf="#+id/viewTaskButtonUIMain"
app:layout_constraintTop_toBottomOf="#+id/viewTaskButtonUIMain"
app:layout_constraintVertical_bias="0.04000002" />
<TextView
android:id="#+id/upCommingTasksTextViewUIMainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/upCommingTasksTextViewUIMainActivityString"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/viewTaskButtonUIMain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/amountOfTasksTextViewUIMain"
app:layout_constraintVertical_bias="0.18" />
<TextView
android:id="#+id/taskNameTextViewUIMainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
app:layout_constraintBottom_toTopOf="#+id/viewTaskButtonUIMain"
app:layout_constraintStart_toStartOf="#+id/upCommingTasksTextViewUIMainActivity"
app:layout_constraintTop_toBottomOf="#+id/upCommingTasksTextViewUIMainActivity"
app:layout_constraintVertical_bias="0.100000024" />
<TextView
android:id="#+id/dateTextViewUIMainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
app:layout_constraintBottom_toTopOf="#+id/viewTaskButtonUIMain"
app:layout_constraintEnd_toEndOf="#+id/taskNameTextViewUIMainActivity"
app:layout_constraintStart_toStartOf="#+id/taskNameTextViewUIMainActivity"
app:layout_constraintTop_toTopOf="#+id/taskNameTextViewUIMainActivity"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/priorityTextViewUIMainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/viewTaskButtonUIMain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toEndOf="#+id/dateTextViewUIMainActivity"
app:layout_constraintTop_toBottomOf="#+id/taskNameTextViewUIMainActivity" />
</androidx.constraintlayout.widget.ConstraintLayout>
/*
HW02
MainActivity.java
*/
package com.example.hw02;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.TextView;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
public class MainActivity extends AppCompatActivity {
//UI Vars
Button viewTaskButtonUIMain;
Button createTaskButtonUIMain;
TextView amountOfTasksTextViewUIMain;
TextView taskNameTextViewUIMainActivity;
TextView dateTextViewUIMainActivity;
TextView priorityTextViewUIMainActivity;
//Java Vars
ArrayList<Tasks> taskArrayList;
ArrayList<String> taskNameList;
int selectedTask;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//UI Vars inst
viewTaskButtonUIMain = findViewById(R.id.viewTaskButtonUIMain);
createTaskButtonUIMain = findViewById(R.id.createTaskButtonUIMain);
amountOfTasksTextViewUIMain = findViewById(R.id.amountOfTasksTextViewUIMain);
dateTextViewUIMainActivity = findViewById(R.id.dateTextViewUIMainActivity);
priorityTextViewUIMainActivity = findViewById(R.id.priorityTextViewUIMainActivity);
taskNameTextViewUIMainActivity = findViewById(R.id.taskNameTextViewUIMainActivity);
//Java Vars inst
taskArrayList = new ArrayList<Tasks>();
//create Tasks
createTaskButtonUIMain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent sendArray1 = new Intent(MainActivity.this,createTask.class );
sendArray1.putExtra("reviewActivityArray",taskArrayList);
startActivity(sendArray1);
}
});
viewTaskButtonUIMain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String[] taskNames = new String[taskArrayList.size()];
for(int i = 0; i < taskNames.length; i++) {
taskNames[i] = taskArrayList.get(i).getTaskName();
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Select Task")
.setItems(taskNames, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent taskDelete = new Intent(MainActivity.this, reviewActivity.class );
taskDelete.putExtra("catch1", taskArrayList);
taskDelete.putExtra("catch2",which);
startActivity(taskDelete);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
}
});
amountOfTasksTextViewUIMain.setText("You have "+ taskArrayList.size() + " tasks");
//This is for the Create Task
if(getIntent() != null && getIntent().getExtras() != null && getIntent().hasExtra("catch")){
taskArrayList = (ArrayList<Tasks>)getIntent().getSerializableExtra("catch");
int vartempsize = taskArrayList.size();//delete
amountOfTasksTextViewUIMain.setText("You have "+ taskArrayList.size() + " tasks");
Collections.sort(taskArrayList);
//if the arrayList isn't empty
if(taskArrayList.isEmpty()==false){
//change the text
String tempName = taskArrayList.get(0).getTaskName();
taskNameTextViewUIMainActivity.setText(tempName);
dateTextViewUIMainActivity.setText(taskArrayList.get(0).returnDate().toString());
priorityTextViewUIMainActivity.setText(taskArrayList.get(0).getPrioty());
}
}
//comming from review
if(getIntent() != null && getIntent().getExtras() != null && getIntent().hasExtra("dead")){
taskArrayList = (ArrayList<Tasks>) getIntent().getSerializableExtra("dead");
Collections.sort(taskArrayList);
}
}
private void sortLists(){
//sorts list
Collections.sort(taskArrayList);
//organize the names
taskNameList.clear();
//adds all the names in the same order as the taskArrayList
for (Tasks var : taskArrayList){
taskNameList.add(var.getTaskName());
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".reviewActivity">
<TextView
android:id="#+id/TaskInformationTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/taskInfromationTextViewUIactivityReviewString"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.13"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.06999999" />
<TextView
android:id="#+id/nameTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/nameTextViewUICreateTextString"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/TaskInformationTextViewUIactivityReview"
app:layout_constraintTop_toBottomOf="#+id/TaskInformationTextViewUIactivityReview"
app:layout_constraintVertical_bias="0.100000024" />
<TextView
android:id="#+id/dateTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dateTextViewUIactivityReviewString"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/nameTextViewUIactivityReview"
app:layout_constraintTop_toBottomOf="#+id/nameTextViewUIactivityReview"
app:layout_constraintVertical_bias="0.050000012" />
<TextView
android:id="#+id/priorityTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priorityTextViewUIactivityReviewString"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/dateTextViewUIactivityReview"
app:layout_constraintTop_toBottomOf="#+id/dateTextViewUIactivityReview"
app:layout_constraintVertical_bias="0.07999998" />
<TextView
android:id="#+id/nameTaskTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#+id/nameTextViewUIactivityReview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/nameTextViewUIactivityReview" />
<TextView
android:id="#+id/dateTaskTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#+id/dateTextViewUIactivityReview"
app:layout_constraintStart_toStartOf="#+id/nameTaskTextViewUIactivityReview" />
<TextView
android:id="#+id/priorityTaskTextViewUIactivityReview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="#+id/priorityTextViewUIactivityReview"
app:layout_constraintStart_toStartOf="#+id/dateTaskTextViewUIactivityReview" />
<Button
android:id="#+id/cancelButtonUIactivityReview"
android:layout_width="114dp"
android:layout_height="54dp"
android:text="#string/cancleButtonUICreateTaskString"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.09"
app:layout_constraintStart_toStartOf="#+id/priorityTextViewUIactivityReview"
app:layout_constraintTop_toBottomOf="#+id/priorityTextViewUIactivityReview"
app:layout_constraintVertical_bias="0.16000003" />
<Button
android:id="#+id/deleteButtonUIactivityReview"
android:layout_width="106dp"
android:layout_height="49dp"
android:text="#string/deleteButtonUIactivityReviewString"
app:layout_constraintBottom_toBottomOf="#+id/cancelButtonUIactivityReview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.58"
app:layout_constraintStart_toEndOf="#+id/cancelButtonUIactivityReview" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.hw02;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
public class reviewActivity extends AppCompatActivity {
ArrayList<Tasks> taskArrayList;
int plank;
Button deleteButtonUIactivityReview;
Button cancelButtonUIactivityReview;
TextView nameTaskTextViewUIactivityReview;
TextView dateTaskTextViewUIactivityReview;
TextView priorityTaskTextViewUIactivityReview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_review);
deleteButtonUIactivityReview = findViewById(R.id.deleteButtonUIactivityReview);
cancelButtonUIactivityReview = findViewById(R.id.cancelButtonUIactivityReview);
deleteButtonUIactivityReview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
taskArrayList.remove(plank);
Intent goHomeDelete = new Intent(reviewActivity.this,MainActivity.class);
goHomeDelete.putExtra("dead",taskArrayList);
startActivity(goHomeDelete);
}
});
cancelButtonUIactivityReview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent goHomeSafe = new Intent(reviewActivity.this,MainActivity.class);
startActivity(goHomeSafe);
}
});
if(getIntent() != null && getIntent().getExtras() != null && getIntent().hasExtra("catch1")){
taskArrayList = (ArrayList<Tasks>) getIntent().getSerializableExtra("catch1");
plank = (int)getIntent().getSerializableExtra("catch2");
}
nameTaskTextViewUIactivityReview.setText(taskArrayList.get(plank).taskName);
dateTaskTextViewUIactivityReview.setText(taskArrayList.get(plank).returnDate().toString());
priorityTaskTextViewUIactivityReview.setText(taskArrayList.get(plank).getPrioty());
}
}

Crash app when adding multiple activities android studio

Hello everybody I got an issue when I trying to run my app in my physical phone and just get crashed at run. its my 5 time making this app, when this happen just close at installing the app. I'm trying to make an app in the main activity two Image buttons and then open anther activity, each one, I checked myself without creating the image buttons. but when I putted the image button the app just get crashed.
here is my code.
ActivityMain.xml
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/blurred"
tools:context=".MainActivity">
<ImageView
android:id="#+id/blurbackground"
android:layout_width="match_parent"
android:layout_height="97dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/backmain" />
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="62dp"
android:text="Welcome!"
android:textColor="#android:color/white"
android:textSize="22sp" />
<TextView
android:id="#+id/txt2"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="7dp"
android:layout_marginTop="114dp"
android:gravity="center"
android:text="Master all professions in the professions guide"
android:textColor="#android:color/white"
android:textColorHighlight="#android:color/black"
android:textSize="18sp"
android:typeface="sans" />
<TextView
android:id="#+id/txt4"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="10dp"
android:layout_marginBottom="348dp"
android:textColorHighlight="#android:color/black"
android:text="Be part of the game and be the master of professions, these guides are collected from users who offer great help in your adventure throughout Azeroth!"
android:textColor="#android:color/white"
android:textStyle="italic"
android:typeface="sans" />
<TextView
android:id="#+id/txt7"
android:layout_width="322dp"
android:layout_height="64dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginBottom="75dp"
android:text="We have classroom guides available for you to master your character if you are fresh and new to the world of Warcraft, dominate your enemies and take the victory!"
android:textColor="#android:color/white"
android:textColorHighlight="#android:color/black" />
<ImageView
android:id="#+id/imageView"
android:layout_width="227dp"
android:layout_height="103dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="66dp"
android:layout_marginLeft="66dp"
android:layout_marginTop="223dp"
app:srcCompat="#drawable/alchem"
tools:scaleType="centerCrop" />
<ImageButton
android:id="#+id/buthorde"
android:layout_width="68dp"
android:layout_height="75dp"
android:layout_alignStart="#+id/imageView"
android:layout_alignParentBottom="true"
android:layout_marginStart="3dp"
android:layout_marginBottom="155dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
app:srcCompat="#drawable/horde" />
<ImageButton
android:id="#+id/butally"
android:layout_width="70dp"
android:layout_height="73dp"
android:layout_alignEnd="#+id/imageView"
android:layout_alignBottom="#+id/buthorde"
android:layout_marginEnd="5dp"
android:layout_marginBottom="3dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
app:srcCompat="#drawable/ally" />
<Button
android:id="#+id/butshow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="21dp"
android:text="Show me!"
android:textAllCaps="false"
android:textStyle="italic"
android:typeface="sans" />
ActivityMain.java
package hordemuzzle.wowprofessions;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Button butonhorde;
private Button butonally;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//--------------------------------------------------------------------------- -------------------------
TextView textView = (TextView) findViewById(R.id.txt1);
textView.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
textView.setText("Welcome!");
TextView textView1 = (TextView) findViewById(R.id.txt2);
textView1.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
textView1.setText("Master all professions in the professions guide");
//----------------------------------------------------------------------------------------------------
butonally=(Button) findViewById(R.id.butally);
butonally.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActally();
}
});
butonhorde=(Button) findViewById(R.id.buthorde);
butonhorde.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActhorde();
}
});
}
public void openActhorde(){
Intent intenth = new Intent(this, Activityhorde.class);
startActivity(intenth);
}
public void openActally(){
Intent intenta = new Intent(this, Activityally.class);
startActivity(intenta);
}
}
Logcat
2018-11-01 23:30:05.204 1051-19358/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
2018-11-01 23:30:05.204 1051-19358/system_process D/OpenGLRenderer: Swap behavior 1
2018-11-01 23:30:05.291 1051-12094/system_process D/GraphicsStats: Buffer count: 4
2018-11-01 23:30:05.291 1051-4361/system_process I/WindowManager: WIN DEATH: Window{3382c8d u0 hordemuzzle.wowprofessions/hordemuzzle.wowprofessions.SplashScreenActivity}
2018-11-01 23:30:05.291 1051-12088/system_process I/ActivityManager: Process hordemuzzle.wowprofessions (pid 24362) has died
2018-11-01 23:30:05.291 1051-12088/system_process D/ActivityManager: cleanUpApplicationRecord -- 24362
Splash screen activity
package hordemuzzle.wowprofessions;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import gr.net.maroulis.library.EasySplashScreen;
import static android.support.v4.os.LocaleListCompat.create;
public class SplashScreenActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EasySplashScreen config = new EasySplashScreen(SplashScreenActivity.this)
.withFullScreen()
.withTargetActivity(MainActivity.class)
.withSplashTimeOut(4000)
.withBackgroundResource(android.R.color.background_dark)
.withLogo(R.drawable.logo);
View easysplashscreen = config.create();
setContentView(easysplashscreen);
}
}
try this
package hordemuzzle.wowprofessions;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//--------------------------------------------------------------------------- -------------------------
TextView textView = (TextView) findViewById(R.id.txt1);
textView.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
textView.setText("Welcome!");
TextView textView1 = (TextView) findViewById(R.id.txt2);
textView1.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/contm.ttf"));
textView1.setText("Master all professions in the professions guide");
//----------------------------------------------------------------------------------------------------
((ImageButton) findViewById(R.id.butally)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActally();
}
});
((ImageButton) findViewById(R.id.buthorde)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActhorde();
}
});
}
public void openActhorde(){
Intent intenth = new Intent(this, Activityhorde.class);
startActivity(intenth);
}
public void openActally(){
Intent intenta = new Intent(this, Activityally.class);
startActivity(intenta);
}
}

What should i do to move to another activity when only special conditions are met

I am making a quiz app. I want the exit page to be displayed when the next button is pressed after last question has been answered. I have a activity_questions.xml and a activity_exit.xml. The xml for activity_questions.xml is :
<?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"
tools:context="com.example.android.crystal.questions">
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="29dp"
android:fontFamily="sans-serif-thin"
android:padding="10dp"
android:text=""
android:textColor="#440027"
android:textSize="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="#+id/edit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text3"
android:layout_margin="30dp"
android:background="#9775AA"
android:hint="Answer"
android:inputType="text"
android:padding="10dp"
android:textSize="20dip" />
<LinearLayout
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edit2"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/answer"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:onClick="onAnswerClick"
android:padding="2dp"
android:text="Okay" />
<Button
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:onClick="onHintClick"
android:padding="2dp"
android:text="Hint" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dp"
android:orientation="vertical"
android:layout_marginTop="26dp"
android:layout_below="#+id/ll"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/tickcross"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="#+id/ll"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/wierdtick" />
<TextView
android:id="#+id/correctornot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tickcross"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Correct!"
android:textColor="#440027"
android:textSize="30dp" />
<Button
android:id="#+id/nextbutton"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Next"
android:onClick="onNextClick"
/>
</LinearLayout>
</RelativeLayout>
And the java is:
package com.example.android.crystal;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
public class questions extends AppCompatActivity {
Random r = new Random();
private boolean done;
private int QuestionNo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_questions);
findViewById(R.id.tickcross).setVisibility(View.INVISIBLE);
findViewById(R.id.correctornot).setVisibility(View.INVISIBLE);
findViewById(R.id.nextbutton).setVisibility(View.INVISIBLE);
String[] questions = getResources().getStringArray(R.array.Questions);
TextView t = (TextView) findViewById(R.id.text3);
t.setText(questions[QuestionNo]);
}
public void onFinishClick(View view){
Intent intent = new Intent(this, exit.class);
startActivity(intent);
}
public static void hideKeyboardFrom(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
public void answersubmitted() {
findViewById(R.id.tickcross).setVisibility(View.VISIBLE);
TranslateAnimation animation = new TranslateAnimation(0, 0, 2000, 0);
animation.setDuration(1000);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
findViewById(R.id.tickcross).startAnimation(animation);
findViewById(R.id.correctornot).setVisibility(View.VISIBLE);
findViewById(R.id.nextbutton).setVisibility(View.VISIBLE);
}
public void onHintClick(View view) {
String[] hints = getResources().getStringArray(R.array.Hints);
Toast toasty = Toast.makeText(getApplicationContext(), hints[QuestionNo], Toast.LENGTH_SHORT);
toasty.show();
}
public void onAnswerClick(View view) {
if (done == false) {
hideKeyboardFrom(this);
String answer = ((EditText) findViewById(R.id.edit2)).getText().toString();
String[] answers = getResources().getStringArray(R.array.Answers);
String correctAnswer = answers[QuestionNo];
correctAnswer = correctAnswer.toUpperCase();
answer = answer.toUpperCase();
if (answer.equals(correctAnswer)) {
TextView t = (TextView) findViewById(R.id.correctornot);
t.setText("CORRECT!");
ImageView i = (ImageView) findViewById(R.id.tickcross);
i.setImageDrawable(getDrawable(R.drawable.wierdtick));
answersubmitted();
} else {
TextView t = (TextView) findViewById(R.id.correctornot);
t.setText("Correct Answer: " + correctAnswer);
ImageView i = (ImageView) findViewById(R.id.tickcross);
i.setImageDrawable(getDrawable(R.drawable.weirdcross));
answersubmitted();
}
done = true;
}
}
public void onNextClick(View view){
if (done){
String[] questions = getResources().getStringArray(R.array.Questions);
if (QuestionNo < (questions.length - 1)) {
QuestionNo += 1;
TextView t = (TextView) findViewById(R.id.text3);
t.setText(questions[QuestionNo]);
findViewById(R.id.tickcross).setVisibility(View.INVISIBLE);
findViewById(R.id.correctornot).setVisibility(View.INVISIBLE);
findViewById(R.id.nextbutton).setVisibility(View.INVISIBLE);
EditText et = (EditText) findViewById(R.id.edit2);
et.setText("");
done = false;
}
else {
onFinishClick();
}
}
}
}
But the onFinishClick() gives an error
Thanks in advance for your help
What should i do to move to another activity when only special conditions are met
Basically, an if-statement and an Intent.
Raw code with no variables added:
if(condition(s)){
Intent i = new Intent(this, TargetActivity.class);
//Put arguments into the intent if you need them...
startActivity(i);
}
You can put it in a thread, in an onClickListener, anywhere and any way you want to execute the code.
As to the error you are receiving, I cannot help you with that until you supply the stacktrace from Logcat
You can do like this:
mNextBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (mQuestionCount < questionList.size()){
// set next question
} else {
// call finish
}
}
});

android add TextView on click of (+) button with setText as 1and in next 2 and so on

I have one textView and two EditText when i am clicking on the plus button the textView and the two EditText should be added ,and i am able to do that .My problem is the when i am adding the TextView the text should be set as 1 then when the TextView is added again then the text should be set as 2 and so on .i am not able set the text by using t1.setText(i).Here is my code-
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity {
Button btnDisplay;
ImageButton btnAdd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAdd = (ImageButton) findViewById(R.id.btnAdd);
btnDisplay = (Button) findViewById(R.id.btnDisplay);
MyLayoutOperation.add(this, btnAdd);
MyLayoutOperation.display(this, btnDisplay);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
MyLayoutOperation.java
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class MyLayoutOperation {
public static void display(final Activity activity, Button btn)
{
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
LinearLayout scrollViewlinerLayout = (LinearLayout) activity.findViewById(R.id.linearLayoutForm);
java.util.ArrayList<String> msg = new ArrayList<String>();
for (int i = 0; i < scrollViewlinerLayout.getChildCount(); i++)
{
LinearLayout innerLayout = (LinearLayout) scrollViewlinerLayout.getChildAt(i);
TextView t2=(TextView)innerLayout.findViewById(R.id.t1);
t2.setText(i);
EditText e1=(EditText)innerLayout.findViewById(R.id.e1);
EditText edit = (EditText) innerLayout.findViewById(R.id.editDes);
msg.add(t2.getText().toString());
msg.add(e1.getText().toString());
msg.add(edit.getText().toString());
}
Toast t = Toast.makeText(activity.getApplicationContext(), msg.toString(), Toast.LENGTH_SHORT);
t.show();
}
});
}
public static void add(final Activity activity, ImageButton btn)
{
final LinearLayout linearLayoutForm = (LinearLayout) activity.findViewById(R.id.linearLayoutForm);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final LinearLayout newView = (LinearLayout)activity.getLayoutInflater().inflate(R.layout.rowdetail, null);
newView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
ImageButton btnRemove = (ImageButton) newView.findViewById(R.id.btnRemove);
btnRemove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
linearLayoutForm.removeView(newView);
}
});
linearLayoutForm.addView(newView);
}
});
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layoutTeste"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/textView1"
android:layout_width="95dp"
android:layout_height="fill_parent"
android:layout_alignBottom="#+id/btnAdd"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/btnAdd"
android:gravity="center_vertical|center_horizontal"
android:text="#string/titleTecnologies"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageButton android:id="#+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/btnAdd"
android:src="#android:drawable/ic_input_add" />
</RelativeLayout>
<ScrollView android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="275dp">
<LinearLayout android:id="#+id/linearLayoutForm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
<Button android:id="#+id/btnDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnDisplay" />
</LinearLayout>
rowdetails.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowdetail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:layout_marginLeft="10dp"
android:id="#+id/t1"/> <requestFocus />
<EditText android:id="#+id/e1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.62"
android:ems="10"
android:inputType="text"> <requestFocus />
</EditText>
<EditText android:id="#+id/editDes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.62"
android:ems="10"
android:inputType="text"> <requestFocus />
</EditText>
<ImageButton android:id="#+id/btnRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/btnRemove"
android:src="#android:drawable/ic_delete" />
</LinearLayout>
Got the answer just do
t2.setText(i+".");

Android Activity stop due to non-working toast

Hello Stack Overflow !
I'm working on an android application for children : Each activity is a question.
For each question, there is two buttons for clue and the answer.
I encounter two issues :
1/ I have to click on a button before change activity, do I need an override or something so I can change of activity without any click required ?
2/ On this activity (code is below), if I click on the button with the id "essai", the activity stop and I came to the previous activity.. Anybody know how I could fix this ?
Thank you in advance !
Here is the java code
package com.beryl.timewaster;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class Activity1 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity1);
}
public void indice1(View v)
{
Toast.makeText(this, "expression", Toast.LENGTH_LONG).show();
}
public void indice2(View v)
{
Toast.makeText(this, "aguéri", Toast.LENGTH_LONG).show();
}
public void essai(View v)
{
Toast.makeText(this, "LOLILO", Toast.LENGTH_LONG).show();
final ImageButton ib2 = (ImageButton) findViewById(R.id.flechegauche1);
ib2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Activity1.this, Accueil.class);
startActivity(intent);
}
});
}}
And here the xml
<AbsoluteLayout
android:id="#+id/absoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxx"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:layout_x="-1dp"
android:layout_y="61dp"
android:text="#string/dev2"
android:textColor="#color/blanc"
android:textSize="25sp"
android:color="#color/blanc" />
<Button
android:id="#+id/Solution2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="259dp"
android:onClick="essai"
android:text="#string/solution"
android:textColor="#color/vertpomme"
android:textSize="30sp" />
<Button
android:id="#+id/indice1de2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="1dp"
android:layout_y="121dp"
android:onClick="indice1"
android:text="#string/indice1"
android:textColor="#color/orange"
android:textSize="30sp" />
<Button
android:id="#+id/indice2de2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="190dp"
android:onClick="indice2"
android:text="#string/indice2"
android:textColor="#color/rouge"
android:textSize="30sp" />>
<ImageButton
android:id="#+id/flechedroite2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="196dp"
android:layout_y="338dp"
android:src="#drawable/flechedroite" />
<ImageButton
android:id="#+id/flechegauche2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="33dp"
android:layout_y="339dp"
android:src="#drawable/flechegauche" />
</AbsoluteLayout>
</RelativeLayout>
Change final ImageButton ib2 = (ImageButton) findViewById(R.id.flechegauche1); to final ImageButton ib2 = (ImageButton) findViewById(R.id.flechegauche2);. You have not declared android:id="#+id/flechegauche1" in your xml

Categories

Resources