Menu
  • HOME
  • TAGS

How to setContentView before super.onCreate while using AppCompat v22.1.0?

android,appcompat,setcontentview,appcompatactivity

Since you want to get some ui elements in the super method, you have to find a way to define the layout in the superclass. It is the reason because you are getting an NPE as described in the other answers. You can use the setContentView() in the superclass, using...

Variable to keep track of contentView, then call inalidateOptionsMenu()

android,android-actionbar,setcontentview

On invalidating menu using invalidateOptionsMenu(), method onPrepareOptionsMenu(android.view.Menu) will be called, not onCreateOptionsMenu(). So you need to override this method, and you need to write code to show menu item or hide menu item. For example @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (mViewMode == 2) { // Need to...

How to use setContentView() in Android

android,android-layout,setcontentview

Here: setContentView(R.layout.refer_footer); No need to call setContentView with refer_footer layout because refer_footer layout is for ListView footer which you are adding using addFooterView : // inflate foooter layout View footer = getLayoutInflater().inflate(R.layout.refer_footer, null, false); // get footer_layout from footer LinearLayout ll = (LinearLayout)footer.findViewById(R.id.footer_layout); // create TextView TextView tv= new TextView(this);...

Android Studio onCreate setContentView

android,setcontentview

Since you are creating a layout through code, you will not see it in the XML view. If you build and run the app, you should see the Button appear. If you would rather see the Button in the XML view, you should modify the main_layout.xml to look like the...

Unable to start the Android application - NullPointerException on Click Listener

android,android-activity,nullpointerexception,onclicklistener,setcontentview

You are getting the NullPointerException because you are referencing a button that is on an XML layout which has not been displayed. (ie, the button is not found on activity_navegacao.xml). For this reason, you should not call setContentView multiple times to change the view, like you are doing in this...

Multiple views in Android [duplicate]

java,android,background-image,android-textview,setcontentview

Do something like this - my_layout.xml file <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/bg"> </LinearLayout> Activity code setContentView(R.layout.my_layout); final TextView theTimer = new TextView(this); LinearLayout ll = (LinearLayout)findViewByID(R.id.ll); ll.addView(theTimer); ...

Android LinearLayout is not redisplayed after changing weights programmatically

android,android-linearlayout,weight,setcontentview

requestLayout() works for me <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical"> <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/seek" android:progress="50" android:max="100"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"...

white screen when using runOnUiThread

android,ontouchlistener,ui-thread,background-thread,setcontentview

The onCreate method runs on the main (UI) thread and your posting a Runnable to run on the main (UI) thread. In that thread you have a loop with while (p_running) so this while loop is running on the UI thread in an infinite loop. You could simply move that...

Using personal SurfaceView on LinearLayout

android,android-linearlayout,surfaceview,double-buffering,setcontentview

Well, I found a functionnal solution : I think the problem was coming from the MCustomDrawableView initialization . I created a new instance of that class from the onCreate method , and not from the xml file . Then, I set it to the contentView: protected void onCreate(Bundle p_savedInstanceState) {...

How to use setContentView(layout_id) second time in main_activity of android code?

android,multiple-views,setcontentview

You should pretty much never call setContentView() more than once. What you're describing is standard backstack behavior. Either start a new Activity whatever layout you're transitioning to, or switch to using Fragments, and add a new Fragment to the backstack instead of calling setContentView(). Both approaches will give you native...

Blank Second Activity page on text input

android,setcontentview

Ok , here is what you are doing TextView textView = new TextView(this); This means you're creating the TextView dynamically. You don't need to do this when you have TextView in xml file, unless you need. For your purpose here, you don't need to create TextView dynamically. What you should...

Reason for NullPointerException if setContentView() is not used

android,layout-inflater,setcontentview

before initializing any view I do not know for certain what you mean by "initializing any view". Given the rest of your question, I am going to interpret this as meaning "call findViewById() on the activity". You need to call setContentView() before calling findViewById(), because otherwise there are no...

setContentView trouble on android

android,setcontentview

It seems that you created a new layout named new_layout. Inside the new layout, you added some views and you try - with the condition in comments - to add a Fragment in your activity. The FragmentManager try to add the new fragment inside R.id.container as follows: .add(R.id.container, new PlaceholderFragment())...