I'm trying to hide Text View that has value from SharedPreferences
but it wont work at all.
here is part of my Code That get Value from SharedPreferences
and set it to the text view
private void CheckChart() {
Order1 order1 = sharedPrefmanager.getInstance(getActivity()).GetOrder1();
Order2 order2 = sharedPrefmanager.getInstance(getActivity()).GetOrder2();
CartStatus CheckCartStats = sharedPrefmanager.getInstance(getActivity()).GetCartStatus();
if (order1.getFoodName() == "null"){
LinearLayoutCartOrder1.setVisibility(GONE);
}
else {
if (CheckCartStats.getCart1Status() == "Full"){
LinearLayoutCartOrder1.setVisibility(View.VISIBLE);
// Cart1Status = "full";
//Fill the cart 1
order1 = sharedPrefmanager.getInstance(getActivity()).GetOrder1();
//Food
FoodCode = order1.getFoodCode();
FoodName = order1.getFoodName();
FoodCount = order1.getFoodCount();
FoodTotalPrice = order1.getFoodTotalPrice();
FoodType = order1.getFoodType();
//Topping Name
ToppingName1 = order1.getToppingName1();
ToppingName2 = order1.getToppingName2();
ToppingName3 = order1.getToppingName3();
ToppingName4 = order1.getToppingName4();
ToppingName5 = order1.getToppingName5();
ToppingName6 = order1.getToppingName6();
ToppingName7 = order1.getToppingName7();
ToppingName8 = order1.getToppingName8();
ToppingName9 = order1.getToppingName9();
ToppingName10 = order1.getToppingName10();
//Topping Price
ToppingPrice1 = order1.getToppingPrice1();
ToppingPrice2 = order1.getToppingPrice2();
ToppingPrice3 = order1.getToppingPrice3();
ToppingPrice4 = order1.getToppingPrice4();
ToppingPrice5 = order1.getToppingPrice5();
ToppingPrice6 = order1.getToppingPrice6();
ToppingPrice7 = order1.getToppingPrice7();
ToppingPrice8 = order1.getToppingPrice8();
ToppingPrice9 = order1.getToppingPrice9();
ToppingPrice10 = order1.getToppingPrice10();
//Total Price
TotalPrice = order1.getTotalPrice();
//If the food is without type then Visibility to food type is gone
if (FoodType == "null"){
TxtvCart1FoodCount.setText(FoodCount);
TxtvCart1FoodName.setText(FoodName);
TxtvCart1FoodPrice.setText(FoodTotalPrice);
TxtvCart1FoodType.setText(FoodType);
TxtvCart1FoodType.setVisibility(GONE);
TxtvCart1Topping1.setText(ToppingName1);
TxtvCart1Topping2.setText(ToppingName2);
TxtvCart1Topping3.setText(ToppingName3);
TxtvCart1Topping4.setText(ToppingName4);
TxtvCart1Topping5.setText(ToppingName5);
TxtvCart1Topping6.setText(ToppingName6);
TxtvCart1Topping7.setText(ToppingName7);
TxtvCart1Topping8.setText(ToppingName8);
TxtvCart1Topping9.setText(ToppingName9);
TxtvCart1Topping10.setText(ToppingName10);
TxtvCart1ToppingPrice1.setText(ToppingPrice1);
TxtvCart1ToppingPrice2.setText(ToppingPrice2);
TxtvCart1ToppingPrice3.setText(ToppingPrice3);
TxtvCart1ToppingPrice4.setText(ToppingPrice4);
TxtvCart1ToppingPrice5.setText(ToppingPrice5);
TxtvCart1ToppingPrice6.setText(ToppingPrice6);
TxtvCart1ToppingPrice7.setText(ToppingPrice7);
TxtvCart1ToppingPrice8.setText(ToppingPrice8);
TxtvCart1ToppingPrice9.setText(ToppingPrice9);
TxtvCart1ToppingPrice10.setText(ToppingPrice10);
TxtvCart1TotalPrice.setText(TotalPrice);
RemoveViewForUnusedTopping();
}
else {
TxtvCart1FoodCount.setText(FoodCount);
TxtvCart1FoodName.setText(FoodName);
TxtvCart1FoodPrice.setText(FoodTotalPrice);
TxtvCart1FoodType.setText(FoodType);
TxtvCart1Topping1.setText(ToppingName1);
TxtvCart1Topping2.setText(ToppingName2);
TxtvCart1Topping3.setText(ToppingName3);
TxtvCart1Topping4.setText(ToppingName4);
TxtvCart1Topping5.setText(ToppingName5);
TxtvCart1Topping6.setText(ToppingName6);
TxtvCart1Topping7.setText(ToppingName7);
TxtvCart1Topping8.setText(ToppingName8);
TxtvCart1Topping9.setText(ToppingName9);
TxtvCart1Topping10.setText(ToppingName10);
TxtvCart1ToppingPrice1.setText(ToppingPrice1);
TxtvCart1ToppingPrice2.setText(ToppingPrice2);
TxtvCart1ToppingPrice3.setText(ToppingPrice3);
TxtvCart1ToppingPrice4.setText(ToppingPrice4);
TxtvCart1ToppingPrice5.setText(ToppingPrice5);
TxtvCart1ToppingPrice6.setText(ToppingPrice6);
TxtvCart1ToppingPrice7.setText(ToppingPrice7);
TxtvCart1ToppingPrice8.setText(ToppingPrice8);
TxtvCart1ToppingPrice9.setText(ToppingPrice9);
TxtvCart1ToppingPrice10.setText(ToppingPrice10);
TxtvCart1TotalPrice.setText(TotalPrice);
RemoveViewForUnusedTopping();
}
}
}
}
and here is the function to hide Unused Topping that have default value "null" from SharedPreferences
private void RemoveViewForUnusedTopping() {
Order1 order1 = sharedPrefmanager.getInstance(getActivity()).GetOrder1();
//Make Unused View Topping Dissapear
//Topping 1
if (order1.getToppingName1() == "null"){
TxtvCart1Topping1.setVisibility(GONE);
TxtvCart1ToppingPrice1.setVisibility(GONE);
TxtvRp1.setVisibility(GONE);
}
else if(order1.getToppingName1() != "null"){
//Topping 1
TxtvCart1Topping1.setVisibility(VISIBLE);
TxtvCart1ToppingPrice1.setVisibility(VISIBLE);
TxtvRp1.setVisibility(VISIBLE);
}
else if(order1.getToppingName2() == "null"){
TxtvCart1Topping2.setVisibility(GONE);
TxtvCart1ToppingPrice2.setVisibility(GONE);
TxtvRp2.setVisibility(GONE);
}
else if(order1.getToppingName2() != "null"){
//Topping 2
TxtvCart1Topping2.setVisibility(VISIBLE);
TxtvCart1ToppingPrice2.setVisibility(VISIBLE);
TxtvRp2.setVisibility(VISIBLE);
}
else if(order1.getToppingName3() == "null"){
TxtvCart1Topping3.setVisibility(GONE);
TxtvCart1ToppingPrice3.setVisibility(GONE);
TxtvRp3.setVisibility(GONE);
}
else if(order1.getToppingName3() != "null"){
//Topping 3
TxtvCart1Topping3.setVisibility(VISIBLE);
TxtvCart1ToppingPrice3.setVisibility(VISIBLE);
TxtvRp3.setVisibility(VISIBLE);
}
else if(order1.getToppingName4() == "null"){
TxtvCart1Topping4.setVisibility(GONE);
TxtvCart1ToppingPrice4.setVisibility(GONE);
TxtvRp4.setVisibility(GONE);
}
else if(order1.getToppingName4() != "null"){
//Topping 4
TxtvCart1Topping4.setVisibility(VISIBLE);
TxtvCart1ToppingPrice4.setVisibility(VISIBLE);
TxtvRp4.setVisibility(VISIBLE);
}
else if(order1.getToppingName5() == "null"){
TxtvCart1Topping5.setVisibility(GONE);
TxtvCart1ToppingPrice5.setVisibility(GONE);
TxtvRp5.setVisibility(GONE);
}
else if(order1.getToppingName5() != "null"){
//Topping 5
TxtvCart1Topping5.setVisibility(VISIBLE);
TxtvCart1ToppingPrice5.setVisibility(VISIBLE);
TxtvRp5.setVisibility(VISIBLE);
}
else if(order1.getToppingName6() == "null"){
TxtvCart1Topping6.setVisibility(GONE);
TxtvCart1ToppingPrice6.setVisibility(GONE);
TxtvRp6.setVisibility(GONE);
}
else if(order1.getToppingName6() != "null"){
//Topping 6
TxtvCart1Topping6.setVisibility(VISIBLE);
TxtvCart1ToppingPrice6.setVisibility(VISIBLE);
TxtvRp6.setVisibility(VISIBLE);
}
else if(order1.getToppingName7() == "null"){
TxtvCart1Topping7.setVisibility(GONE);
TxtvCart1ToppingPrice7.setVisibility(GONE);
TxtvRp7.setVisibility(GONE);
}
else if(order1.getToppingName7() != "null"){
//Topping 7
TxtvCart1Topping7.setVisibility(VISIBLE);
TxtvCart1ToppingPrice7.setVisibility(VISIBLE);
TxtvRp7.setVisibility(VISIBLE);
}
else if(order1.getToppingName8() == "null"){
TxtvCart1Topping8.setVisibility(GONE);
TxtvCart1ToppingPrice8.setVisibility(GONE);
TxtvRp8.setVisibility(GONE);
}
else if(order1.getToppingName8() != "null"){
//Topping 8
TxtvCart1Topping8.setVisibility(VISIBLE);
TxtvCart1ToppingPrice8.setVisibility(VISIBLE);
TxtvRp8.setVisibility(VISIBLE);
}
else if(order1.getToppingName9() == "null"){
TxtvCart1Topping9.setVisibility(GONE);
TxtvCart1ToppingPrice9.setVisibility(GONE);
TxtvRp9.setVisibility(GONE);
}
else if(order1.getToppingName9() != "null"){
//Topping 9
TxtvCart1Topping9.setVisibility(VISIBLE);
TxtvCart1ToppingPrice9.setVisibility(VISIBLE);
TxtvRp9.setVisibility(VISIBLE);
}
else if(order1.getToppingName10() == "null"){
TxtvCart1Topping10.setVisibility(GONE);
TxtvCart1ToppingPrice10.setVisibility(GONE);
TxtvRp10.setVisibility(GONE);
}
else if(order1.getToppingName10() != "null"){
//Topping 10
TxtvCart1Topping10.setVisibility(VISIBLE);
TxtvCart1ToppingPrice10.setVisibility(VISIBLE);
TxtvRp10.setVisibility(VISIBLE);
}
else {
}
}
No matter what I do the Unused topping wont GONE
I already try it to place the RemoveViewForUnusedTopping()
function at button and pressed it still not working.
Is it really possible to hide TextView
that has SharedPreferences
Value set to it ?
Already fixed it after change to the Equal()
and separate the if statement per Textview
and changed it from "null" to "none"
private void RemoveViewForUnusedTopping() {
Order1 order1 = sharedPrefmanager.getInstance(getActivity()).GetOrder1();
//Make Unused View Topping Dissapear
//Topping 1
if (TxtvCart1Topping1.getText().equals("none")){
TxtvCart1Topping1.setVisibility(GONE);
TxtvCart1ToppingPrice1.setVisibility(GONE);
TxtvRp1.setVisibility(GONE);
}
else{
//Topping 1
TxtvCart1Topping1.setVisibility(VISIBLE);
TxtvCart1ToppingPrice1.setVisibility(VISIBLE);
TxtvRp1.setVisibility(VISIBLE);
}
if(TxtvCart1Topping2.getText().equals("none")){
TxtvCart1Topping2.setVisibility(GONE);
TxtvCart1ToppingPrice2.setVisibility(GONE);
TxtvRp2.setVisibility(GONE);
}
else{
//Topping 2
TxtvCart1Topping2.setVisibility(VISIBLE);
TxtvCart1ToppingPrice2.setVisibility(VISIBLE);
TxtvRp2.setVisibility(VISIBLE);
}
if(TxtvCart1Topping3.getText().equals("none")){
TxtvCart1Topping3.setVisibility(GONE);
TxtvCart1ToppingPrice3.setVisibility(GONE);
TxtvRp3.setVisibility(GONE);
}
else{
//Topping 3
TxtvCart1Topping3.setVisibility(VISIBLE);
TxtvCart1ToppingPrice3.setVisibility(VISIBLE);
TxtvRp3.setVisibility(VISIBLE);
}
if(TxtvCart1Topping4.getText().equals("none")){
TxtvCart1Topping4.setVisibility(GONE);
TxtvCart1ToppingPrice4.setVisibility(GONE);
TxtvRp4.setVisibility(GONE);
}
else{
//Topping 4
TxtvCart1Topping4.setVisibility(VISIBLE);
TxtvCart1ToppingPrice4.setVisibility(VISIBLE);
TxtvRp4.setVisibility(VISIBLE);
}
if(TxtvCart1Topping5.getText().equals("none")){
TxtvCart1Topping5.setVisibility(GONE);
TxtvCart1ToppingPrice5.setVisibility(GONE);
TxtvRp5.setVisibility(GONE);
}
else{
//Topping 5
TxtvCart1Topping5.setVisibility(VISIBLE);
TxtvCart1ToppingPrice5.setVisibility(VISIBLE);
TxtvRp5.setVisibility(VISIBLE);
}
if(TxtvCart1Topping6.getText().equals("none")){
TxtvCart1Topping6.setVisibility(GONE);
TxtvCart1ToppingPrice6.setVisibility(GONE);
TxtvRp6.setVisibility(GONE);
}
else{
//Topping 6
TxtvCart1Topping6.setVisibility(VISIBLE);
TxtvCart1ToppingPrice6.setVisibility(VISIBLE);
TxtvRp6.setVisibility(VISIBLE);
}
if(TxtvCart1Topping7.getText().equals("none")){
TxtvCart1Topping7.setVisibility(GONE);
TxtvCart1ToppingPrice7.setVisibility(GONE);
TxtvRp7.setVisibility(GONE);
}
else{
//Topping 7
TxtvCart1Topping7.setVisibility(VISIBLE);
TxtvCart1ToppingPrice7.setVisibility(VISIBLE);
TxtvRp7.setVisibility(VISIBLE);
}
if(TxtvCart1Topping8.getText().equals("none")){
TxtvCart1Topping8.setVisibility(GONE);
TxtvCart1ToppingPrice8.setVisibility(GONE);
TxtvRp8.setVisibility(GONE);
}
else{
//Topping 8
TxtvCart1Topping8.setVisibility(VISIBLE);
TxtvCart1ToppingPrice8.setVisibility(VISIBLE);
TxtvRp8.setVisibility(VISIBLE);
}
if(TxtvCart1Topping9.getText().equals("none")){
TxtvCart1Topping9.setVisibility(GONE);
TxtvCart1ToppingPrice9.setVisibility(GONE);
TxtvRp9.setVisibility(GONE);
}
else{
//Topping 9
TxtvCart1Topping9.setVisibility(VISIBLE);
TxtvCart1ToppingPrice9.setVisibility(VISIBLE);
TxtvRp9.setVisibility(VISIBLE);
}
if(TxtvCart1Topping10.getText().equals("none")){
TxtvCart1Topping10.setVisibility(GONE);
TxtvCart1ToppingPrice10.setVisibility(GONE);
TxtvRp10.setVisibility(GONE);
}
else{
//Topping 10
TxtvCart1Topping10.setVisibility(VISIBLE);
TxtvCart1ToppingPrice10.setVisibility(VISIBLE);
TxtvRp10.setVisibility(VISIBLE);
}
}