Error inflating class android.widget.GridLayout app crash - java

When I try to run my app in Android Studio emulator everything works fine, but when I try to run it on my phone (LG G4) the app crashes and the error on the logs is:
Error inflating class android.widget.GridLayout
Here is my 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=".MainActivity">
<GridLayout
android:id="#+id/gridLayout"
android:layout_width="368dp"
android:layout_height="360dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/board"
android:columnCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:rowCount="3">
<ImageView
android:id="#+id/imageView"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="dropIn"
android:tag="0"
app:layout_column="0"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="dropIn"
android:tag="1"
app:layout_column="1"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="dropIn"
android:tag="2"
app:layout_column="2"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_margin="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:onClick="dropIn"
android:tag="3"
app:layout_column="0"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:onClick="dropIn"
android:tag="4"
app:layout_column="1"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:onClick="dropIn"
android:tag="5"
app:layout_column="2"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:onClick="dropIn"
android:tag="6"
app:layout_column="0"
app:layout_row="2" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:onClick="dropIn"
android:tag="7"
app:layout_column="1"
app:layout_row="2" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:onClick="dropIn"
android:tag="8"
app:layout_column="2"
app:layout_row="2" />
</GridLayout>
<LinearLayout
android:id="#+id/playAgainLayout"
android:layout_width="189dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="100dp"
android:layout_marginRight="8dp"
android:layout_marginStart="100dp"
android:layout_marginTop="8dp"
android:background="#46d65e"
android:orientation="vertical"
android:padding="30dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/gridLayout"
app:layout_constraintHorizontal_bias="0.011"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/winnerMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextView"
android:textSize="30sp" />
<Button
android:id="#+id/playAgainButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="playAgain"
android:text="Play Again" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Here is my java:
public class MainActivity extends AppCompatActivity {
// 0 = yellow, 1 = red;
int activePlayer = 0;
// 2 means unplayed
int [] gameState= {2, 2, 2, 2, 2, 2, 2, 2, 2};
int [] [] winningPositions = {{0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}, {0,4,8}, {2,4,6}};
public void dropIn (View view){
ImageView counter = (ImageView) view;
System.out.println(counter.getTag().toString());
int tappedCounter = Integer.parseInt(counter.getTag().toString());
if (gameState[tappedCounter] == 2) {
gameState[tappedCounter] = activePlayer;
counter.setTranslationY(-1000f);
if (activePlayer == 0) {
counter.setImageResource(R.drawable.yellow);
activePlayer = 1;
} else {
counter.setImageResource(R.drawable.red);
activePlayer = 0;
}
counter.animate().translationYBy(1000f).rotation(360f).setDuration(500);
for (int [] winningPosition : winningPositions){
if (gameState[winningPosition[0]] == gameState[winningPosition[1]] &&
gameState[winningPosition[1]] == gameState[winningPosition[2]] &&
gameState[winningPosition[0]] != 2){
//Someone has won
String winner = "Red";
if (gameState[winningPosition[0]] == 0){
winner = "Yellow";
}
TextView winnerMeassage = (TextView) findViewById(R.id.winnerMessage);
winnerMeassage.setText(winner + " has won!");
LinearLayout layout = (LinearLayout) findViewById(R.id.playAgainLayout);
layout.setVisibility(View.VISIBLE);
}
}
}
}
public void playAgain (View view){
LinearLayout layout = (LinearLayout) findViewById(R.id.playAgainLayout);
layout.setVisibility(View.INVISIBLE);
// 0 = yellow, 1 = red;
activePlayer = 0;
// 2 means unplayed
for (int i = 0 ; i < gameState.length ; i++){
gameState[i] = 2;
}
// setting all the images source to nothing
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
for(int i = 0 ; i<gridLayout.getChildCount() ; i++){
((ImageView) gridLayout.getChildAt(i)).setImageResource(0);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I don't think the code will help but it is here if you want to see it.

Please check your drawable folder. Sometimes when your images are in v24 drawable folder this error happens move your images to drawable folder.

Try withe support library version.
add via gradle
implementation com.android.support:gridlayout-v7:27.1.1
replace <GridLayout> with <android.support.v7.widget.GridLayout>
Also change the import to support library

Related

How to add a history to calculator?

How do I add a history for a calculator in android studio/java? I need it to be only 3 lines of history before it disapears. How do I also show the entire calculation, and not just print out the result?
first one is where i store all my functions, and the 2nd one is primarily just to customize all the calculator buttons, etc.
import static com.example.calculator.R.string.display;
import androidx.appcompat.app.AppCompatActivity;
import org.mariuszgromada.math.mxparser.*;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText display;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = findViewById(R.id.input);
display.setShowSoftInputOnFocus(false);
display.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (getString(R.string.display).equals(display.getText().toString())){
display.setText("");
}
}
});
}
private void updateText(String strToAdd){
String oldStr = display.getText().toString();
int cursorPos = display.getSelectionStart();
String leftStr = oldStr.substring(0, cursorPos); //code that prints the numbers on the screen
String rightStr = oldStr.substring(cursorPos);
if (getString(R.string.display).equals(display.getText().toString())){
display.setText(strToAdd);
display.setSelection(cursorPos + 1);
}
else{
display.setText(String.format("%s%s%s", leftStr, strToAdd, rightStr));
display.setSelection(cursorPos + 1); //moves cursor position to one right
}
}
public void zeroBTN(View view){
updateText("0");
}
public void oneBTN(View view){
updateText("1");
}
public void twoBTN(View view){
updateText("2");
}
public void threeBTN(View view){
updateText("3");
}
public void fourBTN(View view){
updateText("4");
}
public void fiveBTN(View view){
updateText("5");
}
public void sixBTN(View view){
updateText("6");
}
public void sevenBTN(View view){
updateText("7");
}
public void eightBTN(View view){
updateText("8");
}
public void nineBTN(View view){
updateText("9");
}
public void multiplyBTN(View view){
updateText("×");
}
public void divideBTN(View view){
updateText("÷");
}
public void subtractBTN(View view){
updateText("-");
}
public void addBTN(View view){
updateText("+");
}
public void clearBTN(View view){
display.setText("");
}
public void expBTN(View view){
updateText("^");
}
public void parenthesesBTN(View view){
int cursorPos = display.getSelectionStart();
int openPar = 0;
int closedPar = 0;
int textLength = display.getText().length();
for (int i = 0; i < cursorPos; i++){
if (display.getText().toString().substring(i, i+1).equals("(")){
openPar += 1;
}
if (display.getText().toString().substring(i, i+1).equals(")")){
closedPar += 1;
}
}
if (openPar == closedPar || display.getText().toString().substring(textLength - 1, textLength).equals("(")){
updateText("(");
display.setSelection(cursorPos + 1);
}
else if (closedPar < openPar && !display.getText().toString().substring(textLength - 1, textLength).equals("(")){
updateText(")");
}
display.setSelection(cursorPos + 1);
}
public void plusMinusBTN(View view){
updateText("thx for using my calc, you found an easter egg :)");
}
public void decimalBTN(View view){
updateText(".");
}
public void equalBTN(View view){
String userExp = display.getText().toString();
userExp = userExp.replaceAll("÷", "/");
userExp = userExp.replaceAll("×", "*");
Expression exp = new Expression(userExp);
String result = String.valueOf(exp.calculate());
display.setText(result);
display.setSelection(result.length());
}
public void backspaceBTN(View view){
int cursorPos = display.getSelectionStart();
int textLen = display.getText().length();
if (cursorPos != 0 && textLen !=0){ //code to delete stuff
SpannableStringBuilder selection = (SpannableStringBuilder) display.getText();
selection.replace(cursorPos - 1, cursorPos, "");
display.setSelection(cursorPos - 1);
}
}
}
<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">
<TableLayout
android:id="#+id/tableLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/input"
app:layout_constraintVertical_bias="0.95"
tools:layout_editor_absoluteX="1dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/clearBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="clearBTN"
android:text="#string/clear"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/parenthesesBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="parenthesesBTN"
android:text="#string/parentheses"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/exponentBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="expBTN"
android:text="#string/exponent"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/divideBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="divideBTN"
android:text="#string/divide"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/sevenBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="sevenBTN"
android:text="#string/seven"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/eightBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="eightBTN"
android:text="#string/eight"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/nineBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="nineBTN"
android:text="#string/nine"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/multiplyBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="multiplyBTN"
android:text="#string/multiply"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/fourBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="fourBTN"
android:text="#string/four"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/fiveBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="fiveBTN"
android:text="#string/five"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/sixBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="sixBTN"
android:text="#string/six"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/subtractBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="subtractBTN"
android:text="#string/subtract"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/one"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="oneBTN"
android:text="#string/one"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/two"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="twoBTN"
android:text="#string/two"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/three"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="threeBTN"
android:text="#string/three"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/add"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="addBTN"
android:text="#string/add"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/plusMinusBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="plusMinusBTN"
android:text="#string/plusMinus"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/zeroBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="zeroBTN"
android:text="#string/zero"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/pointBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="decimalBTN"
android:text="#string/point"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
<Button
android:id="#+id/equalsBTN"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/circle"
android:onClick="equalBTN"
android:text="#string/equals"
android:textColor="#000000"
android:textSize="24sp"
tools:ignore="UsingOnClickInXml" />
</TableRow>
</TableLayout>
<EditText
android:id="#+id/input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="#string/display"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:autofillHints="false"
android:inputType="none"
android:textSize="36sp"
android:textAlignment="textEnd"
tools:ignore="LabelFor" />
<ImageButton
android:id="#+id/backspace"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/circle"
android:contentDescription="#string/backspace"
android:onClick="backspaceBTN"
app:layout_constraintBottom_toTopOf="#+id/tableLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/backspace"
tools:ignore="UsingOnClickInXml" />
</androidx.constraintlayout.widget.ConstraintLayout>

Android studio checkbox gets unchecked when moved from one screen to next screen

I am new to android studio, I tried all possible options, but unable to understand why checkbox gets unchecked when moved from one screen to other when I come back to previous screen.
I am missing out something in onsavedInstanceState or onRestoreInstanceState
Below is my Java Code
package com.example.qualitycheckstation;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Qc2_1_1 extends AppCompatActivity {
CheckBox qc2_1cb1a,qc2_1cb1b,qc2_1cb1c, qc2_1cb2a,qc2_1cb2b,qc2_1cb2c ,qc2_1cb3a,qc2_1cb3b, qc2_1cb3c;
TextView date2_1_1, time2_1_1;
Button next2_1_1,back2_1_1;
Boolean myBoolean1,myBoolean2,myBoolean3,myBoolean4,myBoolean5,myBoolean6,myBoolean7,myBoolean8,myBoolean9;
private static String pr2_1_1,pr2_1_2,pr2_1_3;
private boolean myBoolean = false;
public static String getPr2_1_1 (){
return pr2_1_1;
}
public static String getPr2_1_2 (){
return pr2_1_2;
}
public static String getPr2_1_3(){
return pr2_1_3;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qc2_1_1);
date2_1_1= findViewById(R.id.date2_1_1);
time2_1_1 = findViewById(R.id.time2_1_1);
Calendar calendar= Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
String date = simpleDateFormat.format(calendar.getTime());
date2_1_1.setText(date);
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("hh:mm:ss a");
String time0 = simpleDateFormat1.format(calendar.getTime());
time2_1_1.setText(time0);
qc2_1cb1a = findViewById(R.id.qc2_1cb1a);
qc2_1cb1b = findViewById(R.id.qc2_1cb1b);
qc2_1cb1c = findViewById(R.id.qc2_1cb1c);
qc2_1cb2a = findViewById(R.id.qc2_1cb2a);
qc2_1cb2b = findViewById(R.id.qc2_1cb2b);
qc2_1cb2c = findViewById(R.id.qc2_1cb2c);
qc2_1cb3a = findViewById(R.id.qc2_1cb3a);
qc2_1cb3b = findViewById(R.id.qc2_1cb3b);
qc2_1cb3c = findViewById(R.id.qc2_1cb3c);
next2_1_1 = findViewById(R.id.next2_1_1);
back2_1_1 = findViewById(R.id.back2_1_1);
next2_1_1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if((qc2_1cb1a.isChecked())){
pr2_1_1 = "O";
}
else if((qc2_1cb1b.isChecked())){
pr2_1_1 = "X";
}
else if((qc2_1cb1c.isChecked())){
pr2_1_1 = "N/A";
}
if((qc2_1cb2a.isChecked())){
pr2_1_2 = "O";
}
else if((qc2_1cb2b.isChecked())){
pr2_1_2 = "X";
}
else if((qc2_1cb2c.isChecked())){
pr2_1_2 = "N/A";
}
if((qc2_1cb3a.isChecked())){
pr2_1_3 = "O";
}
else if((qc2_1cb3b.isChecked())){
pr2_1_3 = "X";
}
else if((qc2_1cb3c.isChecked())){
pr2_1_3 = "N/A";
}
if (
((qc2_1cb1a.isChecked()) && (qc2_1cb1b.isChecked())) || ((qc2_1cb1b.isChecked()) && (qc2_1cb1c.isChecked())) || ((qc2_1cb1a.isChecked()) && (qc2_1cb1c.isChecked())) ||
((qc2_1cb2a.isChecked()) && (qc2_1cb2b.isChecked())) || ((qc2_1cb2b.isChecked()) && (qc2_1cb2c.isChecked())) || ((qc2_1cb2a.isChecked()) && (qc2_1cb2c.isChecked())) ||
((qc2_1cb3a.isChecked()) && (qc2_1cb3b.isChecked())) || ((qc2_1cb3b.isChecked()) && (qc2_1cb3c.isChecked())) || ((qc2_1cb3a.isChecked()) && (qc2_1cb3c.isChecked()))
)
{ { Toast.makeText(getApplicationContext(),"Select Either OK, NG or N/A", Toast.LENGTH_SHORT).show(); }}
else if (
((qc2_1cb1a.isChecked()) || (qc2_1cb1b.isChecked()) || (qc2_1cb1c.isChecked())) &&
((qc2_1cb2a.isChecked()) || (qc2_1cb2b.isChecked()) || (qc2_1cb2c.isChecked()))&&
((qc2_1cb3a.isChecked()) || (qc2_1cb3b.isChecked()) || (qc2_1cb3c.isChecked()))
)
{ Intent intent = new Intent(Qc2_1_1.this, Qc2_1_2.class);startActivity(intent); }
else { Toast.makeText(getApplicationContext(),"Select all parameters", Toast.LENGTH_SHORT).show(); }
}
});
back2_1_1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Qc2_1_1.this, Qc2.class);
startActivity(intent);
}
});
}
#Override
protected void onSaveInstanceState(#NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("qc2_1cb1a", qc2_1cb1a.isChecked());
outState.putBoolean("qc2_1cb1b", qc2_1cb1b.isChecked());
outState.putBoolean("qc2_1cb1c", qc2_1cb1c.isChecked());
outState.putBoolean("qc2_1cb2a", qc2_1cb2a.isChecked());
outState.putBoolean("qc2_1cb2b", qc2_1cb2b.isChecked());
outState.putBoolean("qc2_1cb2c", qc2_1cb2c.isChecked());
outState.putBoolean("qc2_1cb3a", qc2_1cb3a.isChecked());
outState.putBoolean("qc2_1cb3b", qc2_1cb3b.isChecked());
outState.putBoolean("qc2_1cb3c", qc2_1cb3c.isChecked());
}
#Override
protected void onRestoreInstanceState(#NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
myBoolean1 = savedInstanceState.getBoolean("qc2_1cb1a");
myBoolean2 = savedInstanceState.getBoolean("qc2_1cb1b");
myBoolean3 = savedInstanceState.getBoolean("qc2_1cb1c");
myBoolean4 = savedInstanceState.getBoolean("qc2_1cb2a");
myBoolean5 = savedInstanceState.getBoolean("qc2_1cb2b");
myBoolean6 = savedInstanceState.getBoolean("qc2_1cb2c");
myBoolean7 = savedInstanceState.getBoolean("qc2_1cb3a");
myBoolean8 = savedInstanceState.getBoolean("qc2_1cb3b");
myBoolean9 = savedInstanceState.getBoolean("qc2_1cb3c");
qc2_1cb1a.setChecked(myBoolean1);
qc2_1cb1b.setChecked(myBoolean2);
qc2_1cb1c.setChecked(myBoolean3);
qc2_1cb2a.setChecked(myBoolean4);
qc2_1cb2b.setChecked(myBoolean5);
qc2_1cb2c.setChecked(myBoolean6);
qc2_1cb3a.setChecked(myBoolean7);
qc2_1cb3b.setChecked(myBoolean8);
qc2_1cb3c.setChecked(myBoolean9);
}
}
xml Code
<TableLayout
android:layout_width="match_parent"
android:layout_height="462dp"
android:layout_marginStart="15dp"
android:layout_marginTop="125dp"
android:layout_marginEnd="15dp"
android:background="#color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="Sl No"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="Measured Item"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="199dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="OP No"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="2"
android:background="#a3addb"
android:gravity="center"
android:text="Gauge Used"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.5"
android:background="#a3addb"
android:gravity="center"
android:text="Parameter"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="91dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="OK"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="92dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="NG"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:layout_width="96dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="N/A"
android:textColor="#color/black"
android:textSize="25dp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="1."
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="Groove Surface"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="25"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="2"
android:background="#a3addb"
android:gravity="center"
android:text=" Visual"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="131dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.5"
android:background="#a3addb"
android:gravity="center"
android:text="Exist"
android:textColor="#color/black"
android:textSize="25dp" />
<CheckBox
android:id="#+id/qc2_1cb1a"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_green" />
<CheckBox
android:id="#+id/qc2_1cb1b"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_red" />
<CheckBox
android:id="#+id/qc2_1cb1c"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_red" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="2."
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="291dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="Serial Engraving Surface"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="291dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="30"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="41dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="2"
android:background="#a3addb"
android:gravity="center"
android:text=" Visual"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.5"
android:background="#a3addb"
android:gravity="center"
android:text="Numbers should be readable"
android:textColor="#color/black"
android:textSize="25dp" />
<CheckBox
android:id="#+id/qc2_1cb2a"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_green" />
<CheckBox
android:id="#+id/qc2_1cb2b"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_red" />
<CheckBox
android:id="#+id/qc2_1cb2c"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_red" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="125dp"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:gravity="center"
android:text="3."
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="251dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="Machining Surface"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="251dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.25"
android:background="#a3addb"
android:gravity="center"
android:text="25"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="31dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="2"
android:background="#a3addb"
android:gravity="center"
android:text=" Visual"
android:textColor="#color/black"
android:textSize="25dp" />
<TextView
android:layout_width="328dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="1.5"
android:background="#a3addb"
android:gravity="center"
android:text="No rough surface, unwash surface,scratch, burr"
android:textColor="#color/black"
android:textSize="25dp" />
<CheckBox
android:id="#+id/qc2_1cb3a"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_green" />
<CheckBox
android:id="#+id/qc2_1cb3b"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_red" />
<CheckBox
android:id="#+id/qc2_1cb3c"
android:layout_width="64dp"
android:layout_height="match_parent"
android:layout_marginStart="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight=".25"
android:background="#a3addb"
android:button="#drawable/checkbox_red" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="360dp"
android:layout_marginTop="32dp"
android:text="QC Station 2.1"
android:textColor="#color/black"
android:textSize="50dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="211dp"
android:layout_height="68dp"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/logo" />
<TextView
android:id="#+id/date2_1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginEnd="50dp"
android:ems="6"
android:hint="DD/MM/YYYY"
android:inputType="date"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/time2_1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:layout_marginEnd="50dp"
android:ems="6"
android:hint="HH.MM.SS"
android:inputType="time"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/next2_1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginBottom="30dp"
android:background="#drawable/button"
android:text="next"
android:textColor="#color/white"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/back2_1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginBottom="30dp"
android:background="#drawable/button"
android:text="Back"
android:textColor="#color/white"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Any support to solve this would be of great help
You should get values from savedInstanceState in onCreate() method. Someting like:
if (savedInstanceState!=null){
myBoolean1 = savedInstanceState.getBoolean("qc2_1cb1a");
myBoolean2 = savedInstanceState.getBoolean("qc2_1cb1b");
myBoolean3 = savedInstanceState.getBoolean("qc2_1cb1c");
myBoolean4 = savedInstanceState.getBoolean("qc2_1cb2a");
myBoolean5 = savedInstanceState.getBoolean("qc2_1cb2b");
myBoolean6 = savedInstanceState.getBoolean("qc2_1cb2c");
myBoolean7 = savedInstanceState.getBoolean("qc2_1cb3a");
myBoolean8 = savedInstanceState.getBoolean("qc2_1cb3b");
myBoolean9 = savedInstanceState.getBoolean("qc2_1cb3c");
}
and then assign it to your check boxes

Fix Overlapping Collapsing/Expanding Cards Java

I am using Android Studio to create 2 CardViews that expand and collapse on a mouseclick. However, when I expand a card, the card underneath does not get pushed down and still visible even if the card above is expanded and is an overlap problem.
How do i fix this so either the card below the one being expanded gets pushed down or that the card that is being expanded information is at the front?
Screenshot of how cards look before clicked:Before Clicked
screenshot of when when clicked: when clicked (as you can see the 'Steven Smith card is still being shown)
Note: I did look into using a Recycler View + adapter etc. but in each card I would want different layouts/images (vs all being consistent info like a contact in someones phone)
Here is my java code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_engineering_page);
expandableView = findViewById(R.id.expandableView);
arrowBtn = findViewById(R.id.arrowBtn);
cardView = findViewById(R.id.cardView);
arrowBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView.getVisibility()==View.GONE){
TransitionManager.beginDelayedTransition(cardView, new AutoTransition());
expandableView.setVisibility(View.VISIBLE);
arrowBtn.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(cardView, new AutoTransition());
expandableView.setVisibility(View.GONE);
arrowBtn.setBackgroundResource(R.drawable.android_icon);
}
}
});
expandableView2 = findViewById(R.id.expandableView2);
arrowBtn2 = findViewById(R.id.arrowBtn2);
cardView2 = findViewById(R.id.cardView2);
arrowBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView2.getVisibility()==View.GONE){
TransitionManager.beginDelayedTransition(cardView2, new AutoTransition());
expandableView2.setVisibility(View.VISIBLE);
arrowBtn2.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(cardView2, new AutoTransition());
expandableView2.setVisibility(View.GONE);
arrowBtn2.setBackgroundResource(R.drawable.android_icon);
}
}
});
}
}
Here is my XML code:
<?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=".EngineeringPage"
android:background="#22325A">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:background="#C4C4C4"
app:logo="#drawable/image1"
app:title="">
</android.support.v7.widget.Toolbar>
<TextView
android:id="#+id/engineeringTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="409dp"
android:layout_marginEnd="111dp"
android:layout_marginLeft="111dp"
android:layout_marginRight="111dp"
android:layout_marginStart="111dp"
android:layout_marginTop="61dp"
android:text="Engineering"
android:textColor="#android:color/white"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CardView.Light"
android:layout_marginTop="98dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Section 1"
style="#style/TextAppearance.AppCompat.Title"
android:layout_marginStart="12dp" />
<Button
android:id="#+id/arrowBtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:visibility="gone"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="#+id/phoneIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="52dp"
android:layout_marginStart="12dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/phoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="(999) 345 32 45"
android:layout_marginStart="32dp"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/phoneIcon"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc"/>
<TextView
android:id="#+id/phoneDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Mobile"
android:layout_marginStart="32dp"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon"/>
<ImageView
android:id="#+id/mailIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="22dp"
android:layout_marginStart="12dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon"/>
<TextView
android:id="#+id/mailNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="workemail#gmail.com"
android:layout_marginStart="32dp"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/mailIcon"
app:layout_constraintStart_toEndOf="#id/mailIcon"
app:layout_constraintBottom_toTopOf="#+id/mailDesc"/>
<TextView
android:id="#+id/mailDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Work"
android:layout_marginStart="32dp"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintTop_toBottomOf="#+id/mailNumber"
app:layout_constraintStart_toEndOf="#id/mailIcon"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
style="#style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="184dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
android:id="#+id/name2"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="Steven Smith" />
<Button
android:id="#+id/arrowBtn2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingBottom="12dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="#+id/phoneIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:layout_marginTop="52dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/phoneNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="(999) 345 32 45"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toTopOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/phoneDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Mobile"
android:textColor="#8A000000"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber2" />
<ImageView
android:id="#+id/mailIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:layout_marginTop="22dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/mailNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="workemail#gmail.com"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/mailDesc2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toTopOf="#+id/mailIcon2" />
<TextView
android:id="#+id/mailDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Work"
android:textColor="#8A000000"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toBottomOf="#+id/mailNumber2" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
I have modified your sample to make it work correctly, you need to animated the parent layout for the two cardViews to make the animation smoth
java
final ConstraintLayout content = findViewById(R.id.content_layout);
final ConstraintLayout expandableView = findViewById(R.id.expandableView);
final Button arrowBtn = findViewById(R.id.arrowBtn);
arrowBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView.getVisibility() == View.GONE) {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView.setVisibility(View.VISIBLE);
arrowBtn.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView.setVisibility(View.GONE);
arrowBtn.setBackgroundResource(R.drawable.android_icon);
}
}
});
final ConstraintLayout expandableView2 = findViewById(R.id.expandableView2);
final Button arrowBtn2 = findViewById(R.id.arrowBtn2);
arrowBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView2.getVisibility() == View.GONE) {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView2.setVisibility(View.VISIBLE);
arrowBtn2.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView2.setVisibility(View.GONE);
arrowBtn2.setBackgroundResource(R.drawable.android_icon);
}
}
});
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"
android:id="#+id/content_layout"
android:background="#22325A">
<android.support.v7.widget.Toolbar
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/toolbar"
android:background="#C4C4C4"
app:logo="#drawable/logo"
app:title="">
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/CardView.Light"
android:layout_marginTop="98dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Section 1"
style="#style/TextAppearance.AppCompat.Title"
android:layout_marginStart="12dp" />
<Button
android:id="#+id/arrowBtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintTop_toTopOf="#id/name"
app:layout_constraintBottom_toBottomOf="#id/name"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="#id/arrowBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="#+id/phoneIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:src="#drawable/logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/phoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="(999) 345 32 45"
android:layout_marginStart="32dp"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/phoneIcon"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc"/>
<TextView
android:id="#+id/phoneDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Mobile"
app:layout_constraintStart_toStartOf="#id/phoneNumber"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon"/>
<ImageView
android:id="#+id/mailIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="22dp"
android:layout_marginStart="12dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon"/>
<TextView
android:id="#+id/mailNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="workemail#gmail.com"
app:layout_constraintStart_toStartOf="#id/phoneNumber"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/mailIcon"
app:layout_constraintStart_toEndOf="#id/mailIcon"
app:layout_constraintBottom_toTopOf="#+id/mailDesc"/>
<TextView
android:id="#+id/mailDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintStart_toStartOf="#id/phoneNumber"
app:layout_constraintTop_toBottomOf="#+id/mailNumber"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
style="#style/CardView.Light"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardView">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/name2"
style="#style/TextAppearance.AppCompat.Title"
android:layout_marginStart="12dp"
android:text="Steven Smith" />
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintTop_toTopOf="#id/name2"
app:layout_constraintBottom_toBottomOf="#id/name2"
app:layout_constraintEnd_toEndOf="parent"
android:id="#+id/arrowBtn2"
/>
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
app:layout_constraintTop_toBottomOf="#id/arrowBtn2"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="#+id/phoneIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:src="#drawable/logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="#+id/phoneNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="(999) 345 32 45"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toTopOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/phoneDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#id/phoneNumber2"
android:text="Mobile"
android:textColor="#8A000000"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber2" />
<ImageView
android:id="#+id/mailIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:layout_marginTop="22dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/mailNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#id/phoneNumber2"
android:text="workemail#gmail.com"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/mailDesc2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toTopOf="#+id/mailIcon2" />
<TextView
android:id="#+id/mailDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work"
android:textColor="#8A000000"
app:layout_constraintStart_toStartOf="#id/phoneNumber2"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toBottomOf="#+id/mailNumber2" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Just put everything inside a Linear Layout orientation vertical or Inside other layouts align your bottom and tops correctly with android:layout_below="#+id/YOUR ID"

How can I put frames in textviews to have the form of a table?

IMAGE-Something like that
I have begun to create an application that will show us the weather conditions of some cities.My problem is that I do not know how can I put frames in textviews to have the form of a table.If there are any solutions please help me.
My xml code
<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.junior_marg.current_weather.Main12Activity">
<TextView
android:id="#+id/textview12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/c"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview12"
android:layout_marginLeft="20dp"
android:layout_marginStart="92dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/d"
android:layout_below="#+id/textview12"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview14"
android:layout_below="#+id/textview13"
android:layout_marginLeft="50dp"
android:layout_marginStart="133dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/h2"
android:layout_below="#+id/textview14"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview16"
android:layout_marginLeft="20dp"
android:layout_marginStart="77dp"
android:layout_marginTop="63dp" />
<TextView
android:id="#+id/textview18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/i2"
android:layout_below="#+id/textview16"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview18"
android:layout_marginLeft="50dp"
android:layout_marginStart="130dp"
android:layout_marginTop="90dp" />
<TextView
android:id="#+id/textview20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/j2"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/textview18"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview20"
android:layout_below="#+id/textview19"
android:layout_marginLeft="10dp"
android:layout_marginStart="104dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/k2"
android:layout_below="#+id/textview20"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview22"
android:layout_below="#+id/textview21"
android:layout_marginLeft="50dp"
android:layout_marginStart="63dp"
android:layout_marginTop="11dp" />
<TextView
android:id="#+id/textview24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/l2"
android:layout_below="#+id/textview22"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview24"
android:layout_below="#+id/textview23"
android:layout_marginLeft="20dp"
android:layout_marginStart="94dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview26"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/m2"
android:layout_below="#+id/textview24"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview26"
android:layout_below="#+id/textview25"
android:layout_marginLeft="50dp"
android:layout_marginStart="36dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/n2"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/textview26"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview28"
android:layout_below="#+id/textview27"
android:layout_marginLeft="20dp"
android:layout_marginStart="75dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/o2"
android:layout_below="#+id/textview28"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview30"
android:layout_below="#+id/textview29"
android:layout_marginLeft="50dp"
android:layout_marginStart="85dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/p2"
android:layout_below="#+id/textview30"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview32"
android:layout_below="#+id/textview31"
android:layout_marginLeft="20dp"
android:layout_marginStart="73dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/q2"
android:layout_below="#+id/textview32"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview34"
android:layout_below="#+id/textview33"
android:layout_marginLeft="50dp"
android:layout_marginStart="24dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/r2"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/textview34"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview36"
android:layout_below="#+id/textview35"
android:layout_marginLeft="10dp"
android:layout_marginStart="52dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/s2"
android:layout_below="#+id/textview36"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview38"
android:layout_below="#+id/textview37"
android:layout_marginLeft="50dp"
android:layout_marginStart="45dp"
android:layout_marginTop="11dp" />
<TextView
android:id="#+id/textview40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/t2"
android:layout_below="#+id/textview38"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview40"
android:layout_below="#+id/textview39"
android:layout_marginLeft="20dp"
android:layout_marginStart="122dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/textview42"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/u2"
android:layout_below="#+id/textview40"
android:layout_marginLeft="20dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textview43"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textview42"
android:layout_below="#+id/textview41"
android:layout_marginLeft="50dp"
android:layout_marginStart="151dp"
android:layout_marginTop="10dp" />
My java code
TextView mTextView;
TextView mTextView2;
TextView mTextView3;
TextView mTextView4;
TextView mTextView5;
TextView mTextView6;
TextView mTextView7;
TextView mTextView8;
TextView mTextView9;
TextView mTextView10;
TextView mTextView11;
TextView mTextView12;
TextView mTextView13;
TextView mTextView14;
TextView mTextView15;
TextView mTextView16;
String therm;
String ygrasia;
String simdrosou;
String anemos;
String varom;
String simerinosy;
String ragd;
String trexkak;
String miniaiosy;
String ethsiosy;
String aisthpsix;
String yperithriakt;
String deiktisdis;
String hliakiakt;
String anatoli;
String disi;
String url;
Document doc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main12);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
mTextView = (TextView) findViewById(R.id.textview13);
mTextView2 = (TextView) findViewById(R.id.textview15);
mTextView3 = (TextView) findViewById(R.id.textview17);
mTextView4 = (TextView) findViewById(R.id.textview19);
mTextView5 = (TextView) findViewById(R.id.textview21);
mTextView6 = (TextView) findViewById(R.id.textview23);
mTextView7 = (TextView) findViewById(R.id.textview25);
mTextView8 = (TextView) findViewById(R.id.textview27);
mTextView9 = (TextView) findViewById(R.id.textview29);
mTextView10 = (TextView) findViewById(R.id.textview31);
mTextView11 = (TextView) findViewById(R.id.textview33);
mTextView12 = (TextView) findViewById(R.id.textview35);
mTextView13 = (TextView) findViewById(R.id.textview37);
mTextView14 = (TextView) findViewById(R.id.textview39);
mTextView15 = (TextView) findViewById(R.id.textview41);
mTextView16 = (TextView) findViewById(R.id.textview43);
url = "http://penteli.meteo.gr/stations/trikala/";
doc = null;
try {
doc = Jsoup.connect(url).get();
} catch (IOException e) {
e.printStackTrace();
}
Element table = doc.select("table").get(0);
Elements rows = table.select("tr");
Element row = rows.get(5);
Elements cols = row.select("td");
therm = cols.get(1).text() ;
mTextView.setText(therm);
Element row_2 = rows.get(6);
Elements cols_2 = row_2.select("td");
ygrasia = cols_2.get(1).text() ;
mTextView2.setText(ygrasia);
Element row_3 = rows.get(7);
Elements cols_3 = row_3.select("td");
simdrosou = cols_3.get(1).text() ;
mTextView3.setText(simdrosou);
Element row_4 = rows.get(8);
Elements cols_4 = row_4.select("td");
anemos = cols_4.get(1).text() ;
mTextView4.setText(anemos);
Element row_5 = rows.get(9);
Elements cols_5 = row_5.select("td");
varom = cols_5.get(1).text() ;
mTextView5.setText(varom);
Element row_6 = rows.get(10);
Elements cols_6 = row_6.select("td");
simerinosy = cols_6.get(1).text() ;
mTextView6.setText(simerinosy);
Element row_7 = rows.get(11);
Elements cols_7 = row_7.select("td");
ragd = cols_7.get(1).text() ;
mTextView7.setText(ragd);
Element row_8 = rows.get(12);
Elements cols_8 = row_8.select("td");
trexkak = cols_8.get(1).text() ;
mTextView8.setText(trexkak);
Element row_9 = rows.get(13);
Elements cols_9 = row_9.select("td");
miniaiosy = cols_9.get(1).text() ;
mTextView9.setText(miniaiosy);
Element row_10 = rows.get(14);
Elements cols_10 = row_10.select("td");
ethsiosy = cols_10.get(1).text() ;
mTextView10.setText(ethsiosy);
Element row_11 = rows.get(15);
Elements cols_11 = row_11.select("td");
aisthpsix = cols_11.get(1).text() ;
mTextView11.setText(aisthpsix);
Element row_12 = rows.get(16);
Elements cols_12 = row_12.select("td");
yperithriakt = cols_12.get(1).text() ;
mTextView12.setText(yperithriakt);
Element row_13 = rows.get(17);
Elements cols_13 = row_13.select("td");
deiktisdis = cols_13.get(1).text() ;
mTextView13.setText(deiktisdis);
Element row_14 = rows.get(18);
Elements cols_14 = row_14.select("td");
hliakiakt = cols_14.get(1).text() ;
mTextView14.setText(hliakiakt);
Element row_15 = rows.get(19);
Elements cols_15 = row_15.select("td");
anatoli = cols_15.get(1).text() ;
mTextView15.setText(anatoli);
Element row_16 = rows.get(20);
Elements cols_16 = row_16.select("td");
disi = cols_16.get(1).text() ;
mTextView16.setText(disi);
}
}
To get something that resembles a table, I suggest using a TableLayout.
Alternatively, you might try the new FlexboxLayout.

Widget click not responding

I'm trying to set to all of the views that are in the widget a click listener that should open an activity upon a click, but for now seems that its not working. Can someone tell me what am I doing wrong?
Here is my code:
public class AthanWidget extends AppWidgetProvider {
private SharedPreferences prefs;
private boolean PAID = false;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
prefs = context.getSharedPreferences(context.getPackageName(),
Context.MODE_PRIVATE);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String currentDateandTime = sdf.format(new Date());
PAID = prefs.getBoolean(Constants.ITEM_PURCHASED, false);
// TODO CHECK IF IMAGE IS FROM SD OR A RESOURCE IS
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent;
if (!PAID) {
intent = new Intent(context, RemoveAds.class);
} else {
intent = new Intent(context, Main.class);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(appWidgetId, pendingIntent);
views.setTextViewText(R.id.widget_date_title, currentDateandTime);
views.setTextViewText(R.id.widget_arabic_date_title, arabianDate());
displayPrayerTimes(views);
if (prefs.getInt(Constants.BG_ID_PREFS, 1) < 0) {
Bitmap myBitmap = BitmapFactory.decodeFile(prefs.getString(
Constants.BG_SD_PATH, ""));
views.setImageViewBitmap(R.id.widget_bg, myBitmap);
} else {
views.setImageViewResource(R.id.widget_bg,
prefs.getInt(Constants.BG_ID_PREFS, R.drawable.bg24));
}
// Tell the AppWidgetManager to perform an update on the current app
// widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private void displayPrayerTimes(RemoteViews views) {
if (PAID) {
views.setTextViewText(
R.id.widget_fajr,
prefs.getString(Constants.FARJ_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(R.id.widget_dhurh,
prefs.getString(Constants.DHUHR_ID + "w", "DISABLED")
.split(",")[0]);
views.setTextViewText(
R.id.widget_isha,
prefs.getString(Constants.ISHA_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(
R.id.widget_asr,
prefs.getString(Constants.ASR_ID + "w", "DISABLED").split(
",")[0]);
}
views.setTextViewText(
R.id.widget_shorrok,
prefs.getString(Constants.SHORROK_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(
R.id.widget_maghrib,
prefs.getString(Constants.MAGHRIB_ID + "w", "DISABLED").split(
",")[0]);
}
private String arabianDate() {
Date date = new Date(); // هنا التاريخ الصليبي
Calendar cl = Calendar.getInstance();
cl.setTime(date);
final String[] iMonthNames = { "Muharram", "Safar", "Rabi'ul Awwal",
"Rabi'ul Akhir", "Jumadal Ula", "Jumadal Akhira", "Rajab",
"Sha'ban", "Ramadan", "Shawwal", "Dhul Qa'ada", "Dhul Hijja" };
Chronology iso = ISOChronology.getInstanceUTC();
Chronology hijri = IslamicChronology.getInstanceUTC();
LocalDate todayIso = new LocalDate(cl.get(Calendar.YEAR),
cl.get(Calendar.MONTH) + 1, cl.get(Calendar.DAY_OF_MONTH), iso);
LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(),
hijri);
return todayHijri.getDayOfMonth() + " "
+ iMonthNames[todayHijri.getMonthOfYear()] + " "
+ todayHijri.getYear();
}
}
and my widget layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/widget_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".85"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/widget_toptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"
android:text="#string/widget_title"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/widget_date_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/widget_toptext"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/widget_arabic_date_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/widget_date_title"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#80000000"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_sun_up"
android:drawableRight="#drawable/w_pray_sun_up"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_fajr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_fajr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fajr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<!-- delete this -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_sun_up"
android:drawableRight="#drawable/w_pray_sun_up"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_shorok"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_shorrok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shorrok"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_dhurh"
android:drawableRight="#drawable/w_pray_dhurh"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_dhuhr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_dhurh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dhuhr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_asr"
android:drawableRight="#drawable/w_pray_asr"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_asr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_asr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/asr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_maghreb"
android:drawableRight="#drawable/w_pray_maghreb"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_magrib"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_maghrib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maghrib"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_moon"
android:drawableRight="#drawable/w_pray_moon"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_isha"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_isha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/isha_a"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<!-- end of deletion -->
</LinearLayout>
</RelativeLayout>
here you are setting click pending intent for the appwidgetId, but that should be view id.
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(appWidgetId, pendingIntent);
like:
if the id of a Button is R.id.button1. which is in widget layout if you want to set click listener to that button. then that should be like this :
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.button1, pendingIntent);

Categories