Skip to content Skip to sidebar Skip to footer

Set Content View In Android

public class CheckitoutActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setConte

Solution 1:

  1. Remove all other views before setting a new view.
  2. Try debugging the program, I am not sure whether the change() is actually (?) being called. If it is not being called than may be, change() is not recognized by android process callback... You can write your code in onResume().... learn more about Activity class here..As I see change() is not a function in Activity...

    public class Activity extends ApplicationContext { protected void onCreate(Bundle savedInstanceState);

    protectedvoidonStart();
    
     protectedvoidonRestart();
    
     protectedvoidonResume();
    
     protectedvoidonPause();
    
     protectedvoidonStop();
    
     protectedvoidonDestroy();
    

    }

also use @Override with function definitions when you are implementing base class's methods that is a good practice...

Solution 2:

you cannot change Activity's layout on the fly, either you have to remove all the views from the activity first and then add new views to the activity or just use some flipper control to change views dynamically.

Solution 3:

Try to add the event of calling the change() function after setContentView(R.layout.main); ,for example:

Button changeButton=null; 
protectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    changeButton= this.findViewById(R.id.change_button);
    changeButton.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View view) {
            change();
        }
    });
}

Solution 4:

The R.java file is being generated by android itself. It's having case-sensitive. like below code

void change()
{
    setContentView(R.layout.someview);
}

Solution 5:

You are not doing anything, that is like calling two contentviews in the one oncreate(). Use flipviews

Post a Comment for "Set Content View In Android"