Android Fixed Tabs
in
Android Processing
•
2 months ago
Hello,
Tab1 would contain some settings and maybe a Help Button
Tab2 content is a ListView that shows a list of presets. Now I am adding two TextViews for the sake of simplicity.
I am trying with the approach of the Ketai library for KetaiList
So there's an inner class that extends TabHost inside the PApplet class extended by my application:
- public class MyProcessingApp extends PApplet {
- public void setup() {
- }
- public void draw() {
- }
- public void keyPressed() {
- if (key == CODED) {
- if (keyCode == KeyEvent.KEYCODE_MENU) {
- TabHost th = new GBTab(this);
- }
- }
- }
- public class GBTab extends TabHost {
- private PApplet parent;
- TabHost self;
- TabWidget tab1, tab2;
- LinearLayout layout;
- public GBTab(PApplet _parent) {
- super(_parent.getApplicationContext());
- parent = _parent;
- init();
- }
- public void init() {
- println("GBTab init");
- self = this;
- layout = new LinearLayout(parent);
- TabSpec settingsSpec = self.newTabSpec("SETTINGS").setContent(
- new TabContentFactory() {
- public View createTabContent(String tag) {
- TextView tv = new TextView(parent);
- tv.setText("SETTINGS!");
- return tv;
- }
- }
- )
- .setIndicator("SETTINGS");
- self.addTab(settingsSpec);
- TabSpec presetsSpec = self.newTabSpec("PRESETS").setContent(
- new TabContentFactory() {
- public View createTabContent(String tag) {
- TextView tv = new TextView(parent);
- tv.setText("PRESETS!");
- return tv;
- }
- }
- )
- .setIndicator("PRESETS");
- self.addTab(presetsSpec);
- self.setCurrentTab(0);
- parent.runOnUiThread(new Runnable() {
- public void run() {
- parent.addContentView(self, new ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.FILL_PARENT,
- ViewGroup.LayoutParams.FILL_PARENT));
- }
- }
- );
- }
- }
- }
This code gives a NullPointerException when adding a tab to the TabHost.
- self.addTab(settingsSpec);
Is this a valid approach?
Thank you
1