Android actionbar/toolbar disappears after writing to edittext [duplicate] - java

This question already has answers here:
Android Toolbar moves up when keyboard appears
(17 answers)
Closed 4 years ago.
I'm stuck at this. I have an app where I have several pages made as fragments. Every page is good except the last one where when I tap on editText, action bar disappears and when I unfocus it, action bar didn't show up back.
I've tried changing appTheme to all kind of themes but they didn't change anything, most of them forced app to crash.
Here is my layout of that page
<?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$PlaceholderFragment">
<ImageView
android:id="#+id/imageView27"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="#+id/imageView28"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13" />
<ImageView
android:id="#+id/imageView29"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.64"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<ImageView
android:id="#+id/imageView30"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/imageView31"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<ImageView
android:id="#+id/imageView32"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.65" />
<ImageView
android:id="#+id/imageView33"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.78" />
<ImageView
android:id="#+id/imageView34"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.91" />
<TextView
android:id="#+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/houroff"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView27"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.03" />
<TextView
android:id="#+id/minuteOffsetText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minuteoff"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView28"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.16" />
<TextView
android:id="#+id/vinText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vinen"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView29"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.29" />
<TextView
android:id="#+id/defaultText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/defen"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView30"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.40" />
<TextView
android:id="#+id/vhconst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vehicle_const"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView31"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<TextView
android:id="#+id/shft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/output"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView32"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.645" />
<TextView
android:id="#+id/tripText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TRIP\nRESET"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView33"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.76" />
<TextView
android:id="#+id/odoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/odores"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView34"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.895" />
<Switch
android:id="#+id/minOffSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.155" />
<Switch
android:id="#+id/vinSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.285" />
<Switch
android:id="#+id/defaultSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.40" />
<Switch
android:id="#+id/tripResetSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.76" />
<Switch
android:id="#+id/odoResetSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.895" />
<EditText
android:id="#+id/eVehConstSet"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/frame"
android:ems="10"
android:hint="00000"
android:inputType="number"
android:singleLine="true"
android:textAlignment="textEnd"
android:textColor="#android:color/background_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toEndOf="#+id/vhconst"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<EditText
android:id="#+id/eOutShaftSet"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/frame"
android:ems="10"
android:hint="0.000"
android:inputType="number|numberSigned|numberDecimal"
android:singleLine="true"
android:textAlignment="textEnd"
android:textColor="#android:color/background_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toEndOf="#+id/shft"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.645" />
<TextView
android:id="#+id/hourOffset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="0"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.7"
app:layout_constraintStart_toEndOf="#+id/textView25"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.02" />
<TextView
android:id="#+id/minOffset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="0"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.7"
app:layout_constraintStart_toEndOf="#+id/textView25"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13999999" />
<TextView
android:id="#+id/vinResetText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VIN RESET"
android:textAlignment="center"
android:textColor="#android:color/black"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/vinReset"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.29" />
<ImageView
android:id="#+id/vinReset"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<Switch
android:id="#+id/vinResS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.11"
app:layout_constraintStart_toEndOf="#+id/vinResetText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.27999997" />
<TextView
android:id="#+id/pulsem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#drawable/fraction"
android:text="#string/vehicle_const_pm"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/eVehConstSet"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.51" />
<TextView
android:id="#+id/pulser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/fraction"
android:text="#string/output_const"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/eOutShaftSet"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.64" />
and this is my MainActivity
public class MainActivity extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
public static float density = 0;
public static float dpHeight = 0;
public static float dpWidth = 0;
public String macAdress;
public UUID myUUID;
public static int index = 1;
public boolean ConnectSuccess = false;
private ProgressDialog progress;
public BluetoothSocket btSocket = null;
public BluetoothAdapter mBluetooth = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
}
#Override
public void onPageSelected(int position) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
TextView t = findViewById(R.id.title);
switch (position+1){
case 1:
t.setText("Virtual TG Setup");
break;
case 2:
t.setText("Virtual TG Live");
break;
case 3:
t.setText("Virtual TG Config");
break;
}
}
#Override
public void onPageScrollStateChanged(int state) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
}
});
Display d = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
d.getMetrics(outMetrics);
density = getResources().getDisplayMetrics().density;
dpHeight = outMetrics.heightPixels / density;
dpWidth = outMetrics.widthPixels / density;
System.out.println(density);
System.out.println(dpHeight);
System.out.println(dpWidth);
System.out.println(outMetrics.heightPixels);
System.out.println(outMetrics.widthPixels);
Intent intent = getIntent();
macAdress = intent.getStringExtra("EXTRA");
if (macAdress != null) {
new BTConnect().execute();
} else {
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

You can try to set windowSoftInputMode in manifest. Choose which is most suitable for you.
<activity android:name="com.example.app.MainActivity"
android:windowSoftInputMode="adjustResize">

Related

Not able to click the logout and posy buttons

I have tried checking if any layout is overlapping or not. I have tried adding more space between the button and the border nothing seems to work. I'm not able to see where am I missing out
This is the activity where I'm trying to add setonclicklistenr:
public class addPost extends AppCompatActivity {
ImageView picgal,postt;
EditText descrip,compName;
Button pst,logout;
FirebaseAuth auth;
FirebaseStorage storage;
FirebaseDatabase database;
Uri uri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_post);
picgal = findViewById(R.id.addpic);
descrip = findViewById(R.id.postDescription);
logout = findViewById(R.id.lgout);
compName = findViewById(R.id.comm);
auth = FirebaseAuth.getInstance();
storage = FirebaseStorage.getInstance();
logout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
auth.signOut();
startActivity(new Intent(addPost.this,postActivity.class));
}
});
This is the xml file:
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/lgout"
android:layout_width="75dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:background="#drawable/post_button_blue"
android:enabled="false"
android:text="LOGOUT"
android:textColor="#000000"
app:layout_constraintBottom_toBottomOf="#+id/postButton"
app:layout_constraintEnd_toStartOf="#+id/postButton"
app:layout_constraintTop_toTopOf="#+id/postButton"
tools:ignore="TouchTargetSizeCheck" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:fontFamily="#font/roboto_black"
android:text="Create Post"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="#+id/postButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/postButton" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/postButton"
android:layout_width="75dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/post_button_white"
android:enabled="false"
android:text="post"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="TouchTargetSizeCheck" />
<View
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="#CFC9C9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/postButton" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="User1"
android:textColor="#color/black"
android:textSize="#dimen/_14font_mdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view" />
<EditText
android:id="#+id/comm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#android:color/transparent"
android:ems="10"
android:hint="Enter Company Name"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/name"
app:layout_constraintTop_toBottomOf="#+id/name" />
<EditText
android:id="#+id/postDescription"
android:layout_width="355dp"
android:layout_height="287dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:background="#android:color/transparent"
android:ems="10"
android:gravity="top"
android:hint="Type to add your experience"
android:inputType="textMultiLine"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/name"
app:layout_constraintTop_toBottomOf="#+id/comm"
tools:ignore="TouchTargetSizeCheck" />
<ImageView
android:id="#+id/postpic"
android:layout_width="400dp"
android:layout_height="272dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:scaleType="centerCrop"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/view3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/postDescription"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/postDescription"
app:srcCompat="#drawable/img2"
tools:visibility="invisible" />
<ImageView
android:id="#+id/addpic"
android:layout_width="41dp"
android:layout_height="43dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/imgg" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Add to post"
android:textColor="#color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="#+id/addpic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/addpic" />
<View
android:id="#+id/view3"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="#CFC9C9"
app:layout_constraintBottom_toTopOf="#+id/addpic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshot of the .XML file design
I can See You are setting "enabled=false" in logout Button could you remove that part or replace with "enabled=true"...I will work if you do so ..please try

sending data of two fragments to firebase (Fragment wise or in one go)

I have two fragments in one activity. In the first fragment, I have fields like name, email, gender and phone number and by the next button replace with second fragment and on the second fragment, I have a password and confirm password fields. Now I want to send data to firebase fragment-wise or send data of two fragments at one time(by pressing the register button which is on the second fragment).but did not know how to do that
//First Fragment
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/purple_200"
tools:context=".CustomerRegisterFragment">
<ImageView
android:id="#+id/imageView"
android:layout_width="131dp"
android:layout_height="46dp"
android:src="#drawable/logo"
android:textAlignment="center"
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.18"
tools:ignore="MissingConstraints"
android:contentDescription="TODO" />
<TextView
android:id="#+id/textViewCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/personal_details"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="bold"
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.28"
tools:ignore="MissingConstraints" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
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.439"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:fontFamily="#font/courbd"
android:text="#string/user_name"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserName"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="textPersonName"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/user_email"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserEmail"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="textEmailAddress"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout1"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="Phone #:"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserPhone"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="phone"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:fontFamily="#font/courbd"
android:text="#string/user_gender"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="true"
android:clickable="false"
android:focusableInTouchMode="true"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_male"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="false"
android:clickable="false"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_female"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="false"
android:clickable="false"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_other"
android:textColor="#color/black" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnRegisterCustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="71dp"
android:layout_marginBottom="120dp"
android:background="#drawable/button_style"
android:text="#string/btn_next"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3" />
</androidx.constraintlayout.widget.ConstraintLayout>
//Second Fragment
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/purple_200"
tools:context=".CustomerRegisterFragment1">
<ImageView
android:id="#+id/imageView"
android:layout_width="131dp"
android:layout_height="46dp"
android:src="#drawable/logo"
android:textAlignment="center"
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.18"
tools:ignore="MissingConstraints"
android:contentDescription="TODO" />
<TextView
android:id="#+id/textViewCustomerPassTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/c_password"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="bold"
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.28"
tools:ignore="MissingConstraints" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/CustomerRegisterFragment1.linearLayout"
android:layout_centerVertical="true"
android:layout_marginBottom="288dp"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewCustomerPassTitle"
tools:ignore="MissingConstraints">
<EditText
android:id="#+id/editTextCustomerPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#695547"
android:fontFamily="#font/courbd"
android:hint="#string/customer_password"
android:inputType="textPassword"
android:textColor="#color/black"
android:textColorHint="#A88973" />
<EditText
android:id="#+id/editTextCustomerConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#695547"
android:fontFamily="#font/courbd"
android:hint="#string/cconfirm_password"
android:inputType="textPassword"
android:textColor="#color/black"
android:textColorHint="#A88973" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnRegisterCustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="67dp"
android:layout_marginBottom="123dp"
android:background="#drawable/button_style"
android:text="#string/btn_register_client"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/CustomerRegisterFragment1.linearLayout"
app:layout_constraintVertical_bias="0.229" />
</androidx.constraintlayout.widget.ConstraintLayout>
Interface;
interface:
public interface FragmentInterface {
String getName();
String getEmail();
String getPassword();
}
Fragment:
public class FragmentA extend Fragment implements FragmentInterface{}
public class FragmentB extend Fragment implements FragmentInterface{}
xxxActivity:
FragmentInterface fia = (FragmentInterface)FragmentA;
FragmentInterface fib = (FragmentInterface)FragmentB;
get Field:
String name = fia.getName();
String pw = fib.getPassword();
BroadcastReceiver
Global singleton
you have to use bundle in fragment to pass data from one fragment to another
Without Arch. Component...
send data to another fragment
Fragment fragment = new ProductdetailFragment();
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_main,fragment);
transaction.addToBackStack(null);
transaction.commit();
Bundle bundle = new Bundle();
bundle.putString("product_id","value");
bundle.putString("product_name","value");
bundle.putString("price","value");
bundle.putString("product_desc","value");
bundle.putString("product_image",productmodels.get(position).getProduct_image());
fragment.setArguments(bundle);
get data from the previous fragment. for getting data, you have to use key of apply of the previous fragment.do not mismatch key argument
Bundle bundle = getArguments();
String product_id = bundle.getString("product_id");
String name = bundle.getString("product_name");
String price = bundle.getString("price");
String description = bundle.getString("product_desc");
String imageurl = bundle.getString("product_image");
Second Way if You use Navigation Arch. Component
Bundle bundle = new Bundle();
bundle.putString("amount", amount);
Navigation.findNavController(view).navigate(R.id.confirmationAction, bundle);

EditText getText not working in Button Click

I have two EditText in MyActivity. Here I have provided UI XML.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button_insta"
android:layout_width="135dp"
android:layout_height="0dp"
android:layout_marginBottom="33dp"
android:text="Download"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/editUrli"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="18dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:textColor="#0C0C0C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView2"
android:layout_width="177dp"
android:layout_height="39dp"
android:layout_marginEnd="81dp"
android:layout_marginRight="81dp"
android:text="Paste Instagram video link to download "
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/imageView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView3"
app:layout_constraintTop_toTopOf="#+id/imageView3" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="78dp"
android:layout_height="43dp"
android:layout_marginStart="41dp"
android:layout_marginLeft="41dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:src="#drawable/insta"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/card"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="8dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editUrl"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="18dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:textColor="#0C0C0C"
app:layout_constraintBottom_toTopOf="#+id/button_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_download"
android:layout_width="135dp"
android:layout_height="0dp"
android:layout_marginBottom="33dp"
android:text="Download"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/fblogo"
android:layout_width="95dp"
android:layout_height="39dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="13dp"
android:contentDescription="TODO"
android:src="#drawable/fb"
app:layout_constraintBottom_toTopOf="#+id/editUrl"
app:layout_constraintEnd_toStartOf="#+id/textView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="75dp"
android:layout_marginRight="75dp"
android:layout_marginBottom="84dp"
android:text="Paste FB video link to download"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/button_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fblogo"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
In my Activity java code has this button click code
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download);
inputURl = findViewById(R.id.editUrl);
editUrlinsta = findViewById(R.id.editUrli);
BtnDownload = (Button) findViewById(R.id.button_download);
downloadinsta = (Button) findViewById(R.id.button_insta);
BtnDownload.setOnClickListener(this);
downloadinsta.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button_download:
try{
final FacebookDownloader downloaders = new FacebookDownloader(Download.this,inputURl.getText().toString());
downloaders.DownloadVideo();
inputURl.getText().clear();
} catch(Exception e) {}
break;
case R.id.button_insta:
final InstaDownloader downloaderInsta = new InstaDownloader(Download.this,editUrlinsta.getText().toString());
downloaderInsta.DownloadVideo();
editUrlinsta.getText().clear();
break;
default:
break;
}
}
The problem is The first button which I have named button_download is working as expected. But the second button button_insta not working as expected. what I want to do, is When one of the buttons clicks, getting data from EditText. The button_download works fine. the button_insta is not working fine.
I couldn't get value from editUrli when the button click. But same code works for button_download and editUrl
Try to separate those button click function like so :
BtnDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try{
final FacebookDownloader downloaders = new FacebookDownloader(Download.this,inputURl.getText().toString());
downloaders.DownloadVideo();
inputURl.getText().clear();
} catch(Exception e) {}
}
});
downloadinsta.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final InstaDownloader downloaderInsta = new InstaDownloader(Download.this,editUrlinsta.getText().toString());
downloaderInsta.DownloadVideo();
editUrlinsta.getText().clear();
}
});

Why is my Text Change Listener not working?

Why is my "addTextChangedListener" on android not working? Here is my code:
activity_ticketing.xml
<?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=".TicketingMain.Ticketing">
<!-- Main Content -->
<!-- HEADING -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:layout_marginStart="28dp"
android:layout_marginBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/icon_exit" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:minHeight="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView_route"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:text="Tacloban - Tanawan"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.285" />
<TextView
android:id="#+id/textView_vehicle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:text="ZZZ999"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/textView_route"
app:layout_constraintStart_toStartOf="#+id/textView_route"
app:layout_constraintTop_toBottomOf="#+id/textView_route" />
<TextView
android:id="#+id/textView_driver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Driver Name"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView_route"
app:layout_constraintTop_toTopOf="#+id/textView_route" />
<TextView
android:id="#+id/textView_conductor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:text="Conductor Name"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView_vehicle"
app:layout_constraintTop_toBottomOf="#+id/textView_driver" />
<TextView
android:id="#+id/textView_numberOfPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="0"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Passengers"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!-- HEADING END -->
<!-- ROUTEPOST ORIGIN -->
<!-- ROUTEPOST ORIGIN END -->
<!-- MAIN -->
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/materialCardView">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- spinner_direction -->
<Spinner
android:id="#+id/spinner_direction"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="#+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<!-- textView_currentPost -->
<TextView
android:id="#+id/textView_currentPost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#drawable/border_box"
android:text="Current"
android:textAlignment="center"
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/button_prev"
app:layout_constraintEnd_toStartOf="#+id/button_next"
app:layout_constraintStart_toEndOf="#+id/button_prev"
app:layout_constraintTop_toTopOf="#+id/button_prev" />
<!-- button_next -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:textAlignment="center"
app:icon="#drawable/ic_right_arrow"
app:iconGravity="textStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView_currentPost"
app:layout_constraintTop_toBottomOf="#+id/spinner_direction" />
<!-- button_prev -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textStyle="bold"
app:icon="#drawable/ic_left"
app:iconGravity="textStart"
app:layout_constraintEnd_toStartOf="#+id/textView_currentPost"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner_direction" />
<!-- button_postCurrentRoutePost -->
<!-- button_logout -->
<!-- textView = "Direction" -->
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Direction"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- textView_currentLocation -->
<TextView
android:id="#+id/textView_currentLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="No current location set"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="#+id/button_next"
app:layout_constraintStart_toStartOf="#+id/button_prev"
app:layout_constraintTop_toBottomOf="#+id/textView_currentPost" />
<!-- button_nextDestination -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_nextDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAlignment="center"
app:icon="#drawable/ic_right_arrow"
app:iconGravity="textStart"
app:layout_constraintEnd_toEndOf="#+id/textView_currentLocation"
app:layout_constraintStart_toEndOf="#+id/textView_currentPost"
app:layout_constraintTop_toBottomOf="#+id/textView_currentLocation" />
<!-- button_prevDestination -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_prevDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:textAlignment="center"
android:textStyle="bold"
app:icon="#drawable/ic_left"
app:iconGravity="textStart"
app:layout_constraintEnd_toStartOf="#+id/textView_currentPost"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_currentLocation" />
<!-- textView_currentPostDestination -->
<TextView
android:id="#+id/textView_currentPostDestination"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#drawable/border_box"
android:text="Current"
android:textAlignment="center"
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"
android:clickable="true"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="#+id/button_prevDestination"
app:layout_constraintEnd_toStartOf="#+id/button_nextDestination"
app:layout_constraintStart_toEndOf="#+id/button_prevDestination"
app:layout_constraintTop_toTopOf="#+id/button_nextDestination" />
<com.google.android.material.button.MaterialButton
android:id="#+id/button_postDestination"
style="#style/Widget.MaterialComponents.Button"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_marginTop="8dp"
android:text="Submit Destination"
android:textAlignment="center"
app:iconGravity="textStart"
app:layout_constraintEnd_toEndOf="#+id/button_nextDestination"
app:layout_constraintStart_toStartOf="#+id/textView_currentPostDestination"
app:layout_constraintTop_toBottomOf="#+id/textView_currentPostDestination" />
<!-- RECEIPT -->
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView3"
android:layout_width="347dp"
android:layout_height="332dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_postDestination">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="Destination"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView_receiptDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Tacloban - Tanawan"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView4"
app:layout_constraintTop_toTopOf="#+id/textView4" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Passengers"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="#+id/textView4"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textView_receiptPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="0"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView6"
app:layout_constraintTop_toTopOf="#+id/textView6" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Fare"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="#+id/textView6"
app:layout_constraintTop_toBottomOf="#+id/textView6" />
<TextView
android:id="#+id/textView_receiptFare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/textView_receiptPassengers"
app:layout_constraintTop_toTopOf="#+id/textView8" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Total Due"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="#+id/textView8"
app:layout_constraintTop_toBottomOf="#+id/textView8" />
<TextView
android:id="#+id/textView_receiptTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/textView_receiptFare"
app:layout_constraintTop_toTopOf="#+id/textView10" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView4"
android:layout_width="108dp"
android:layout_height="97dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="#+id/textView_receiptTotal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_receiptDestination">
<ImageView
android:id="#+id/imageView_qrCode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />
</com.google.android.material.card.MaterialCardView>
<RadioGroup
android:id="#+id/radioGroup_discount"
android:layout_width="205dp"
android:layout_height="106dp"
android:layout_marginEnd="140dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10"
app:layout_constraintVertical_bias="0.615">
<RadioButton
android:id="#+id/radioButton_noDiscount"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:checked="true"
android:text="No Discount"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<RadioButton
android:id="#+id/radioButton_ssDiscount"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:text="Senior/Student"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<RadioButton
android:id="#+id/radioButton_spDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:text="Special Discount"
android:textSize="12sp"
android:textStyle="bold" />
</RadioGroup>
<Button
android:id="#+id/button_accept"
android:layout_width="108dp"
android:layout_height="74dp"
android:text="Accept"
app:backgroundTint="#009688"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/materialCardView4"
app:layout_constraintStart_toStartOf="#+id/materialCardView4"
app:layout_constraintTop_toBottomOf="#+id/materialCardView4" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!-- <SearchView-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="0dp"-->
<!-- android:id="#+id/search"-->
<!-- app:layout_constraintBottom_toBottomOf="#+id/button_postDestination"-->
<!-- app:layout_constraintEnd_toEndOf="#+id/button_prevDestination"-->
<!-- app:layout_constraintStart_toStartOf="#+id/button_prevDestination"-->
<!-- app:layout_constraintTop_toTopOf="#+id/button_postDestination" />-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="#+id/editText"
app:layout_constraintBottom_toBottomOf="#+id/button_postDestination"
app:layout_constraintEnd_toEndOf="#+id/button_prevDestination"
app:layout_constraintStart_toStartOf="#+id/button_prevDestination"
app:layout_constraintTop_toBottomOf="#+id/button_prevDestination">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textKm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Km" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!-- MAIN END -->
<!-- MAIN -->
<!-- HEADING -->
<!-- LOGOUT -->
<!-- LOGOUT END -->
</androidx.constraintlayout.widget.ConstraintLayout>
Ticketing.java
EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ticketing);
editText = (EditText) findViewById(R.id.textKm);
editText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.e("TEXT", "A");
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.e("TEXT", "A");
}
#Override
public void afterTextChanged(Editable s) {
Log.e("TEXT", "A");
}
});
}
I don't get any error. On debugging, it doesn't stop on any of the overrides.
You can set in tow way
First Way:
EditText et_auto_complete_edit_text;
et_auto_complete_edit_text = findViewById(R.id.et_auto_complete_edit_text);
et_auto_complete_edit_text.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
s.toString()
}
});
XML:
<EditText
android:id="#+id/et_auto_complete_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="8"
android:background="#color/gray_light_EA"
android:drawableRight="#mipmap/ic_search_new"
android:drawablePadding="#dimen/margin5dp"
android:hint="Search here"
android:inputType="text"
android:maxLines="1"
android:padding="10dp"
android:textColor="#color/black"
android:textColorHint="#color/grey"
android:visibility="visible" />
Second Way :
SearchView search;
search = findViewById(R.id.search);
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
fetchData(query);
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
//collectionProductsListAdapter.getFilter().filter(newText);
return false;
}
});
search.setOnSearchClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
search.setOnCloseListener(new SearchView.OnCloseListener() {
#Override
public boolean onClose() {
return false;
}
});
XML:
<androidx.appcompat.widget.SearchView
xmlns:n2="http://schemas.android.com/tools"
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
n2:searchIcon="#mipmap/ic_et_search" />
Hope this may help you first way is more easy.
Try changing it to EditText
<android.support.design.widget.TextInputLayout
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Km"
app:layout_constraintEnd_toEndOf="#+id/button_prevDestination"
app:layout_constraintStart_toStartOf="#+id/button_prevDestination"
app:layout_constraintTop_toBottomOf="#+id/textView_currentPostDestination">
<EditText
android:id="#+id/textKm"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
Working fine in my code.

Application stops when i change everything in a button/textview except the Text

im using 2 Android Books and android-studio to get into the materia but now im stuck.
If i try to change .clickable(false), .setenabled(false) or even the color in Java, my programm stops. It runs fluent with every gimmick im implementing but if i try to enable (first state disabled) the checkboxes/buttons, when someone clicks on the "startbutton", my app closes.
Note about the ammount of Textviews and checkboxes: Im about to check out the mainfunctions and make it in the 1.0 in a scrollable activity with an objectarray. atm all these textviews are only there to get me a hint how big this app can be. It´s a quizapp for exams about health and medicine. It is possible that there is 1 question 10 subquestions and 10 answers or 1 questions, 0 subquestions and only 2 answers. Every Exam has about 60 Questions. BUT i can´t do this cause when i disable one single checkbox or setVisebility(false) my App stops.
My suggestions:
to open a "getCurentState()" method in the xml File
create a new xml file with one "true" and a "false" varable and ref them in the main xml document setclickable="#.../currentState"
ivé heard about xsl but how? :D
XML-File:
<TextView
android:id="#+id/examchoosen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.983"
app:layout_constraintHorizontal_bias="0.92" />
<Button
android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintVertical_bias="0.982" />
<TextView
android:id="#+id/countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.016"
app:layout_constraintHorizontal_bias="0.501" />
<TextView
android:id="#+id/frage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="42dp"
app:layout_constraintHorizontal_bias="0.065"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.022" />
<TextView
android:id="#+id/subfrage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="84dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="#+id/subfrage2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="101dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="#+id/subfrage3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="118dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/subfrage4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="135dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="#+id/subfrage5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="152dp" />
<TextView
android:id="#+id/subfrage6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="169dp" />
<TextView
android:id="#+id/subfrage7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="186dp" />
<TextView
android:id="#+id/subfrage8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="203dp" />
<TextView
android:id="#+id/subfrage9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="220dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.103" />
<TextView
android:id="#+id/subfrage10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="237dp" />
<TextView
android:id="#+id/AntwortA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="273dp" />
<TextView
android:id="#+id/AntwortB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="290dp" />
<TextView
android:id="#+id/AntwortC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="307dp" />
<TextView
android:id="#+id/AntwortD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="325dp" />
<TextView
android:id="#+id/AntwortE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="342dp" />
<TextView
android:id="#+id/AntwortF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="359dp" />
<TextView
android:id="#+id/AntwortG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="376dp" />
<TextView
android:id="#+id/AntwortH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="393dp" />
<TextView
android:id="#+id/AntwortI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="410dp" />
<TextView
android:id="#+id/AntwortJ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_editor_absoluteY="427dp" />
<CheckBox
android:id="#+id/BoxA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="206dp" />
<CheckBox
android:id="#+id/BoxB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="189dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="#+id/BoxC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="172dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="#+id/BoxD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="155dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="#+id/BoxE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="137dp"
app:layout_constraintHorizontal_bias="0.113" />
<CheckBox
android:id="#+id/BoxF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="120dp"
app:layout_constraintHorizontal_bias="0.023" />
<CheckBox
android:id="#+id/BoxG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="103dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="#+id/BoxH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="86dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="#+id/BoxI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="69dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.113"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<CheckBox
android:id="#+id/BoxJ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="52dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.023"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Java File:
package de.isolde_richter.hp_pruefer_00;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class examenExaminer extends AppCompatActivity {
TextView frage;
TextView subfrage1;
TextView subfrage2;
TextView subfrage3;
TextView subfrage4;
TextView subfrage5;
TextView subfrage6;
TextView subfrage7;
TextView subfrage8;
TextView subfrage9;
TextView subfrage10;
TextView antwortA;
TextView antwortB;
TextView antwortC;
TextView antwortD;
TextView antwortE;
TextView antwortF;
TextView antwortG;
TextView antwortH;
TextView antwortI;
TextView antwortJ;
CheckBox BoxA;
CheckBox BoxB;
CheckBox BoxC;
CheckBox BoxD;
CheckBox BoxE;
CheckBox BoxF;
CheckBox BoxG;
CheckBox BoxH;
CheckBox BoxI;
CheckBox BoxJ;
TextView examchoosen;
Button counter;
TextView countdown;
CountDownTimer counterTimer;
#Override
protected void onCreate(Bundle savedInstanceState) {
frage = (TextView) findViewById(R.id.frage);
subfrage1 = (TextView) findViewById(R.id.subfrage1);
subfrage2 = (TextView) findViewById(R.id.subfrage2);
subfrage3 = (TextView) findViewById(R.id.subfrage3);
subfrage4 = (TextView) findViewById(R.id.subfrage4);
subfrage5 = (TextView) findViewById(R.id.subfrage5);
subfrage6 = (TextView) findViewById(R.id.subfrage6);
subfrage7 = (TextView) findViewById(R.id.subfrage7);
subfrage8 = (TextView) findViewById(R.id.subfrage8);
subfrage9 = (TextView) findViewById(R.id.subfrage9);
subfrage10 = (TextView) findViewById(R.id.subfrage10);
antwortA=(TextView) findViewById(R.id.AntwortA);
antwortB=(TextView) findViewById(R.id.AntwortB);
antwortC=(TextView) findViewById(R.id.AntwortC);
antwortD=(TextView) findViewById(R.id.AntwortD);
antwortE=(TextView) findViewById(R.id.AntwortE);
antwortF=(TextView) findViewById(R.id.AntwortF);
antwortG=(TextView) findViewById(R.id.AntwortG);
antwortH=(TextView) findViewById(R.id.AntwortH);
antwortI=(TextView) findViewById(R.id.AntwortI);
antwortJ=(TextView) findViewById(R.id.AntwortJ);
BoxA =(CheckBox)findViewById(R.id.BoxA);
BoxB =(CheckBox)findViewById(R.id.BoxB);
BoxC =(CheckBox)findViewById(R.id.BoxC);
BoxD =(CheckBox)findViewById(R.id.BoxD);
BoxE =(CheckBox)findViewById(R.id.BoxE);
BoxF =(CheckBox)findViewById(R.id.BoxF);
BoxG =(CheckBox)findViewById(R.id.BoxG);
BoxH =(CheckBox)findViewById(R.id.BoxH);
BoxI =(CheckBox)findViewById(R.id.BoxI);
BoxJ =(CheckBox)findViewById(R.id.BoxJ);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_examen_examiner);
examchoosen = (TextView) findViewById(R.id.examchoosen);
counter = (Button) findViewById(R.id.counter);
countdown = (TextView) findViewById(R.id.countdown);
countdown.setText("(120M:00S)");
counter.setText(R.string.rdy);
counterTimer = new CountDownTimer(7200000,100) {
#Override
public void onTick(long l) {
Long totals =(l/100)/10;
Long m = totals/60;
Long s = totals%60;
//countdown.setText(""+m+"M:"+s+"S");
if(m>=10 && s >=10){
countdown.setText("("+m+"M:"+s+"S)"); //bsp 1 = (10M:10S)
} else if (m < 10 && s >=10) {
countdown.setText("(0"+m+"M:"+s+"S)"); //bsp 2 = (09M:10S)
} else if (m < 10 && s < 10) {
countdown.setText("(0"+ m+"M:0"+s+"S)"); //bsp 3 (09M:09S)
} else if (m == 0 && s<10){
countdown.setText("(00M:0"+s+"S)");//bsp 5 (00M:09S)
} else if (m >= 10 && s < 10){
countdown.setText("("+m+"M:0"+s+"S)"); //bsp 1 = (10M:09S)
}
}
#Override
public void onFinish() {
countdown.setText("(00M:00S)");
counter.setText("Fertig");
}
};
counter.setOnClickListener(new View.OnClickListener(){
private boolean startExam=false;
#Override
public void onClick(View w){
//wenn der button geklickt wird
//if the button gets clicked
if(startExam==false) {
counter.setText(R.string.next); // <- Works
counterTimer.start();
startExam = true;
}
}
});
}
}
If someone encounters this problem this should help you, in my case it worked.
instead of
listview.setVisibility(true);
do this:
listview.setVisibility(View.VISIBLE);
same thing for Buttons,Textviews or Checkboxes.
checkBox.setChecked(true); //that won´t work if you add dynamically in a listview or linearlayout
checkBox.toggle(); // will do the job, maybe it will work with .setChecked(!ischecked); but i had more problems with it
As far as i have worked with android-studio, i recognised that if you use true/false (boolean) or a fixed number (even if the settings are 1 and 0) for colors in coding, your app will have many problems and won´t run fluent. In an activity you need to speak to the Parentclass (View) and select the variable viá dot. View.VISIBLE (which is an int) View.INVISIBLE (which is also an int)
Hope this will help someone, cause i didn´t got an propper solution for my problem. Android requiers an int instead of a boolean, even if the constructor want´s a boolean. Crazy stuff.

Categories