Answer the question
In order to leave comments, you need to log in
Is it possible using Enum to make the Layout toggle different colors?
Good day to all. I have such a task. I need to make the color of the Layout change when I click on the smartphone screen ... I solved this problem, but now I started to study enum (enumerations) and caught fire with such a question. Is it possible to switch Layout with different colors using Enum? And I can't seem to figure out how to do it. Can you point out what I'm doing wrong. Where to read what to solve this problem.
package com.example.screern;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
enum Colors {
Red, Blue, Yellow;
}
public class MainActivity extends Activity implements OnClickListener{
LinearLayout linearLayout1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout1 = (LinearLayout)findViewById(R.id.LinearLayout1);
linearLayout1.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
Colors color;
color = Colors.Red;
color = Colors.Yellow;
switch (color) {
case Red:
linearLayout1.setBackgroundColor(Color.RED);
break;
case Yellow:
linearLayout1.setBackgroundColor(Color.YELLOW);
break;
default:
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question