I don't know what to compare in my if statements for my order.setOnClickerListener to get my code working properly. I'm trying to setText based on which image is selected from the array when the button is pressed.
public class Breakfast extends AppCompatActivity {
Integer[]Foods = {R.drawable.pancakes, R.drawable.frenchtoast, R.drawable.waffles,
R.drawable.omelet};
ImageView pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.activity_breakfast); GridView grid = (GridView) findViewById(R.id.gridView);
final ImageView pic = (ImageView) findViewById(R.id.imgLarge);
final TextView food = (TextView) findViewById(R.id.txtFood);
Button back = (Button) findViewById(R.id.btnBack);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Breakfast.this, MainActivity.class));
}
});
final Button order = (Button) findViewById(R.id.btnOrder);
order.setEnabled(false);
order.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Foods[0] == ****){
Toast.makeText(getBaseContext(), "Pancakes added to your order", Toast.LENGTH_SHORT).show();
food.setText("You've selected Pankcakes");}
if(Foods[1] == ****){
Toast.makeText(getBaseContext(), "French Toast added to your order", Toast.LENGTH_SHORT).show();
food.setText("You've selected French Toast");}
if(Foods[2] == ****){
Toast.makeText(getBaseContext(), "Waffles added to your order", Toast.LENGTH_SHORT).show();
food.setText("You've selected Waffles");}
if(Foods[3] == ****){
Toast.makeText(getBaseContext(), "Omelet added to your order", Toast.LENGTH_SHORT).show();
food.setText("You've selected Omelet");}
}
});
grid.setAdapter(new ImageAdapter(this));
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
pic.setImageResource(Foods[position]);
order.setEnabled(true);
}
});
}
}
There's a little more code but I don't think it's relevant.
Aucun commentaire:
Enregistrer un commentaire