Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm creating a small animation app using Android studio. When a button press images should work according to the particular animation.

There's an error with line viewGroup = (viewGroup)findViewById(R.id.ViewGroup);

It shows " Cannot resolve symbol ViewGroup ". I typed Alt+Enter and selected a solution. But nothing happened.

public class MainActivity extends Activity {
private ViewGroup viewGroup;
private ImageView imageView, imageView2, imageView3,imageView4,imageView5,imageView6,imageView7,imageView8,imageView9,imageView10,imageView11,imageView12;
private Button button,button1;
@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    viewGroup=(viewGroup)findViewById(R.id.ViewGroup);
    imageView= (ImageView) findViewById(R.id.imageView);
    imageView2= (ImageView) findViewById(R.id.imageView2);
    imageView3= (ImageView) findViewById(R.id.imageView3);
    imageView4= (ImageView) findViewById(R.id.imageView4);
    imageView5= (ImageView) findViewById(R.id.imageView5);
    imageView6=(ImageView) findViewById(R.id.imageView6);
    imageView7=(ImageView) findViewById(R.id.imageView7);
    imageView8=(ImageView) findViewById(R.id.imageView8);
    imageView9=(ImageView) findViewById(R.id.imageView9);
    imageView10=(ImageView) findViewById(R.id.imageView10);
    imageView11=(ImageView) findViewById(R.id.imageView11);
    imageView12=(ImageView) findViewById(R.id.imageView12);
    button = (Button)findViewById(R.id.button);
    button1=(Button)findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            TransitionManager.beginDelayedTransition(viewGroup, new Fade());
            fade(imageView, imageView2, imageView3,imageView4,imageView5,imageView6);
    button.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v) {
            TransitionManager.beginDelayedTransition(viewGroup, new Slide());
            toggle(imageView7,imageView8,imageView9,imageView10,imageView11,imageView12);
private static void toggle(View... views) {
    for (View v : views) {
        boolean isVisible = v.getVisibility() == View.VISIBLE;
        v.setVisibility(isVisible ? View.INVISIBLE :
                View.VISIBLE);
private static void fade(View... views) {
    for (View v : views) {
        boolean isVisible = v.getVisibility() == View.VISIBLE;
        v.setVisibility(isVisible ? View.INVISIBLE :
                View.VISIBLE);

Here's my activity_main xml

<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/myAniLayout">
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="44dp" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button1"
    android:layout_alignBottom="@+id/button"
    android:layout_alignParentEnd="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@mipmap/ic_launcher" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:src="@mipmap/ic_launcher"
    android:layout_below="@+id/imageView"
    android:layout_alignParentStart="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView3"
    android:src="@mipmap/ic_launcher"
    android:layout_alignTop="@+id/imageView2"
    android:layout_alignParentEnd="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView4"
    android:src="@mipmap/ic_launcher"
    android:layout_below="@+id/imageView2"
    android:layout_centerHorizontal="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView5"
    android:src="@mipmap/ic_launcher"
    android:layout_below="@+id/imageView4"
    android:layout_alignParentStart="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView6"
    android:src="@mipmap/ic_launcher"
    android:layout_below="@+id/imageView4"
    android:layout_alignParentEnd="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView7"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@android:drawable/star_big_on" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView8"
    android:src="@android:drawable/star_big_on"
    android:layout_below="@+id/imageView7"
    android:layout_alignParentStart="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView9"
    android:src="@android:drawable/star_big_on"
    android:layout_below="@+id/imageView7"
    android:layout_alignParentEnd="true" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView10"
    android:src="@android:drawable/star_big_on"
    android:layout_below="@+id/imageView9"
    android:layout_alignStart="@+id/button1" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView11"
    android:src="@android:drawable/star_big_on"
    android:layout_below="@+id/imageView8"
    android:layout_alignEnd="@+id/button" />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView12"
    android:src="@android:drawable/star_big_on"
    android:layout_above="@+id/button"
    android:layout_alignStart="@+id/imageView4" />
  

The ViewGroup class is a subclass of the View class. ViewGroup instances work as containers for View instances to group View instances together.

http://developer.android.com/intl/es/reference/android/view/ViewGroup.html

As per your xml there is not an any id with ViewGroup in your xml code. please give id to your layout with ViewGroup and cast it as below,

viewGroup=(ViewGroup)findViewById(R.id.ViewGroup);

there was also a spelling mistake in your line,

viewGroup=(viewGroup)findViewById(R.id.ViewGroup);

As they pointed out, you have no R.id.ViewGroup in your layout.

If you really need the view group try this:

viewGroup = (ViewGroup)findViewById(android.R.id.content)
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.