Question

I'm writing application without UI layout xml files, so i have this class:

package com.bps.spec;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;

public class SPEC extends ActionBarActivity {
    private ViewPager viewPager;
    private SearchPanel searchPanel;
    private EditorManager editorManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewPager = new ViewPager(this);

        searchPanel = new SearchPanel(this);
        viewPager.addView(searchPanel, 0);

        editorManager = new EditorManager(this);
        viewPager.addView(editorManager, 1);

        setContentView(viewPager);
    }
}

Classes SearchPanel and EditorManager are extending LinearLayout class, im sure they are ok, i tested them without viewPager.

public class SearchPanel extends LinearLayout {
    private TextView searchLabel;
    private EditText searchEntry;
    private ListView listView;

    public SearchPanel(Context context) {
        super(context);
        setOrientation(LinearLayout.VERTICAL);
        setGravity(Gravity.FILL_HORIZONTAL);

        searchLabel = new TextView(context);
        searchLabel.setText("Wyszukaj");
        addView(searchLabel);

        searchEntry = new EditText(context);
        addView(searchEntry);

        listView = new ListView(context);
        addView(listView);
    }

}

public class EditorManager extends LinearLayout {
    private EditText editText;

    public EditorManager(Context context) {
        super(context);
        setOrientation(LinearLayout.HORIZONTAL | LinearLayout.VERTICAL);
        setGravity(Gravity.FILL);

        editText = new EditText(context);
        addView(editText);
    }

}

The problem is i cant see my widgets on screen only blank activity :(

Should I do something more to show them?

Was it helpful?

Solution

I'm writing application without UI layout xml files

Why?

The problem is i cant see my widgets on screen only blank activity

To use a ViewPager, you do not call addView(). Instead, you create a PagerAdapter that will return pages as needed, and attach the PagerAdapter to the ViewPager using setAdapter().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top