Grim
Grim

Reputation: 1996

View not added to application

I am confused. This is my Action:

public class ZoppenActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final HostnameChecker c = new HostnameChecker();
        c.execute(this);
    }
}

And this is my zoppen_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000">
</View>

The preview (GraphicalLayout-Tab) has a black background, but if i debug the Application, there is no black background. It looks like the view is never added to the application.

What did i wrong?

Upvotes: 0

Views: 38

Answers (1)

冯思源
冯思源

Reputation: 26

You need use setContentView in Activity to load the View.So add it into onCreate.

public class ZoppenActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zoppen_main);
        final HostnameChecker c = new HostnameChecker();
        c.execute(this);
    }
}

Upvotes: 1

Related Questions