What I want is for the user to be able to click a TextView, after which a DialogBox pops up, and if the User clicks on the positive button, a Boolean value is changed from False to True.
It is for purchasing items in app items with in app currency.
Example: Inside the TextView, the item name is given, (Special Fruit), when the TextView is clicked a DialogBox pops up, asking, Are you sure you want to purchase this item? Yes/No. If user clicks on yes and had clicked on TExtView A, I want a Boolean A to change to true where default value was false.
Here is the code so far
public class ShopScreen extends AppCompatActivity {
private TextView TV1, TV2, TV3, TV4, TV5;
private boolean B1, B2, B3, B4, B5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop_screen);
B1 = false;
B2 = false;
B3 = false;
B4 = false;
B5 = false;
TV1 = findViewById(R.id.TextOne);
TV2 = findViewById(R.id.TextTwo);
TV3 = findViewById(R.id.TextThree);
TV4 = findViewById(R.id.TextFour);
TV5 = findViewById(R.id.TextFive);
TV1.setText("Special Fruit");
TV1.setText("Apple Munch");
TV1.setText("Watermelon Pop");
TV1.setText("Passionfruit Blast");
TV1.setText("Strawberry Explosion");
TV1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fruitPurchase();
}
});
TV2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fruitPurchase();
}
});
TV3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fruitPurchase();
}
});
TV4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fruitPurchase();
}
});
TV5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fruitPurchase();
}
});
}
public void fruitPurchase () {
AlertDialog.Builder DBuild = new AlertDialog.Builder(ShopScreen.this);
LayoutInflater DInflater = ShopScreen.this.getLayoutInflater();
View DView = DInflater.inflate(R.layout.ao_dialog, null);
DBuild.setView(DView)
.setTitle("Confirm")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Completely confused about what to do from here.
switch () {
case R.id.TV1;
// If TV1 was Selected, I want boolean B1 to change from false to true.
B1 = true;
break;
case R.id.TV2;
B1 = true;
break;
}
}
});
DBuild.show();
}
public void changeviews () {
if (B1 = true) {
TV1.setText("Sold Out");
TV1.setClickable(false);
}
}
I would really appreciate any help you could offer.
question from:
https://stackoverflow.com/questions/66046932/need-help-regarding-textviews-dialogboxes-boolean-statements-and-switch-cases 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…