Example usage for android.widget TabHost setup

List of usage examples for android.widget TabHost setup

Introduction

In this page you can find the example usage for android.widget TabHost setup.

Prototype

public void setup() 

Source Link

Document

Call setup() before adding tabs if loading TabHost using findViewById().

Usage

From source file:ru.gkpromtech.exhibition.events.EventsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // restore saved positions
    int savedPosition = 0;
    if (savedInstanceState != null) {
        savedFilter = savedInstanceState.getInt(SAVE_FILTER, EventReader.EVENT_FILTER_ALL);
        savedPosition = savedInstanceState.getInt(SAVE_PAGE_NUMBER, 0);
    } else {/*  www .  j  a  v  a2s  .c  om*/
        // calculate day to position ViewPager
        Calendar calendar = Calendar.getInstance();
        Date d = calendar.getTime();
        List<Date> days = new ArrayList<>(EventReader.getInstance(this).getDays());
        if (days.contains(d))
            savedPosition = days.indexOf(d);
    }

    FrameLayout view = (FrameLayout) findViewById(R.id.container);
    getLayoutInflater().inflate(R.layout.activity_events, view, true);

    TabHost tabHost = (TabHost) view.findViewById(R.id.tabHost);
    tabHost.setup();

    tabHost.addTab(tabHost
            .newTabSpec("tag" + EventReader.EVENT_FILTER_ALL).setIndicator(createIndicatorView(tabHost,
                    getResources().getString(R.string.all_uppercase), R.drawable.ic_events_all))
            .setContent(R.id.tab1));

    tabHost.addTab(tabHost
            .newTabSpec("tag" + EventReader.EVENT_FILTER_SHOW).setIndicator(createIndicatorView(tabHost,
                    getResources().getString(R.string.event_status_business), R.drawable.ic_white_plane))
            .setContent(R.id.tab2));

    tabHost.addTab(tabHost
            .newTabSpec("tag" + EventReader.EVENT_FILTER_MY).setIndicator(createIndicatorView(tabHost,
                    getResources().getString(R.string.event_status_my), R.drawable.ic_person))
            .setContent(R.id.tab3));

    pager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new EventsFragmentPagerAdapter(getSupportFragmentManager(), EventReader.getInstance(this),
            savedFilter);
    pager.setAdapter(pagerAdapter);

    // set saved page
    pager.setCurrentItem(savedPosition);
    tabHost.setCurrentTabByTag("tag" + savedFilter);

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            switch (tabId) {
            case "tag" + EventReader.EVENT_FILTER_ALL:
                savedFilter = EventReader.EVENT_FILTER_ALL;
                break;
            case "tag" + EventReader.EVENT_FILTER_SHOW:
                savedFilter = EventReader.EVENT_FILTER_SHOW;
                break;
            case "tag" + EventReader.EVENT_FILTER_MY:
                savedFilter = EventReader.EVENT_FILTER_MY;
                break;
            }
            AnalyticsManager.sendEvent(EventsActivity.this, R.string.events_category, R.string.action_change,
                    savedFilter);
            pagerAdapter.setFilter(savedFilter);
        }
    });

    AnalyticsManager.sendEvent(this, R.string.events_category, R.string.action_open, savedFilter);
}

From source file:com.redhorse.quickstart.AppConfig.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    dbStart = new dbStartConfigAdapter(this);
    dbStart.open();/*from  w  w w  .j a  v a2 s .  c om*/

    loadApps(); // do this in onresume?

    setContentView(R.layout.applist);
    TabHost mTabHost = (TabHost) findViewById(R.id.tabhost);
    mTabHost.setup();
    LayoutInflater inflater_tab1 = LayoutInflater.from(this);
    inflater_tab1.inflate(R.layout.grid1, mTabHost.getTabContentView());
    inflater_tab1.inflate(R.layout.grid2, mTabHost.getTabContentView());
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1")
            .setIndicator("", getResources().getDrawable(R.drawable.btn_add)).setContent(R.id.list1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
            .setIndicator("", getResources().getDrawable(R.drawable.btn_remove)).setContent(R.id.list2));
    mList = (GridView) findViewById(R.id.list1);
    mList.setAdapter(new AppsAdapter());
    mList.setOnItemClickListener(Grid1ItemClickListener);
    mList2 = (GridView) findViewById(R.id.list2);
    mList2.setAdapter(new AppsAdapter2());
    mList2.setOnItemClickListener(Grid2ItemClickListener);
    Button button = (Button) findViewById(R.id.Button01);
    button.setOnClickListener(Button01Listener);
    button = (Button) findViewById(R.id.Button02);
    button.setOnClickListener(Button02Listener);
    button = (Button) findViewById(R.id.weibolist);
    button.setOnClickListener(weibolistListener);
}

From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java

@NonNull
@Override//from   w w w .jav  a2s .  c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    SessionInfo sessionInfo = getSessionInfo();
    List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags();
    if (tags != null && tags.size() > 0) {
        TreeMap<String, Long> map = new TreeMap<>();
        for (Object o : tags) {
            if (o instanceof Map) {
                Map<?, ?> mapTag = (Map<?, ?>) o;
                long uid = MapUtils.getMapLong(mapTag, "uid", 0);
                String name = MapUtils.getMapString(mapTag, "name", "??");
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                if (type == 3) {
                    // type-name will be "Manual" :(
                    name = "Tag: " + name;
                } else {
                    String typeName = MapUtils.getMapString(mapTag, "type-name", null);
                    if (typeName != null) {
                        name = typeName + ": " + name;
                    }
                }
                map.put(name, uid);
            }
        }

        long[] vals = new long[map.size()];
        String[] strings = map.keySet().toArray(new String[map.keySet().size()]);
        for (int i = 0; i < vals.length; i++) {
            vals[i] = map.get(strings[i]);
        }

        filterByList = new ValueStringArray(vals, strings);
    }

    if (filterByList == null) {
        filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list);
    }

    AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(),
            R.layout.dialog_filter_by);

    View view = alertDialogBuilder.view;
    AlertDialog.Builder builder = alertDialogBuilder.builder;

    // get our tabHost from the xml
    TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost);
    tabHost.setup();

    // create tab 1
    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setIndicator("States");
    spec1.setContent(R.id.filterby_sv_state);
    tabHost.addTab(spec1);
    //create tab2
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setIndicator("Tags");
    spec2.setContent(R.id.filterby_tv_tags);
    tabHost.addTab(spec2);

    int height = AndroidUtilsUI.dpToPx(32);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;

    TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state);
    tvState.setMovementMethod(LinkMovementMethod.getInstance());

    final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags);
    tvTags.setMovementMethod(LinkMovementMethod.getInstance());

    // for API <= 10 (maybe 11?), otherwise tags will display on one line
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (!tabId.equals("tab2")) {
                return;
            }
            tvTags.post(new Runnable() {
                @Override
                public void run() {
                    spanTags.updateTags();
                }
            });
        }
    });

    builder.setTitle(R.string.filterby_title);

    // Add action buttons
    builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (mapSelectedTag == null) {
                return;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            String name = MapUtils.getMapString(mapSelectedTag, "name", "??");

            mListener.filterBy(uidSelected, name, true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DialogFragmentFilterByTags.this.getDialog().cancel();
        }
    });

    List<Map<?, ?>> manualTags = new ArrayList<>();
    List<Map<?, ?>> stateTags = new ArrayList<>();

    if (sessionInfo != null) {
        // Dialog never gets called wehn getTags has no tags
        List<Map<?, ?>> allTags = sessionInfo.getTags();
        if (allTags != null) {
            for (Map<?, ?> mapTag : allTags) {
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                switch (type) {
                case 0:
                case 1:
                case 2:
                    stateTags.add(mapTag);
                    break;
                case 3: // manual
                    manualTags.add(mapTag);
                    break;
                }
            }
        }
    }

    SpanTagsListener l = new SpanTagsListener() {
        @Override
        public void tagClicked(Map mapTag, String name) {
            mapSelectedTag = mapTag;
            // todo: long click, don't exit
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            mListener.filterBy(uidSelected, name, true);
            DialogFragmentFilterByTags.this.getDialog().dismiss();
        }

        @Override
        public int getTagState(Map mapTag, String name) {
            if (mapSelectedTag == null) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            if (uidSelected == -1) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1);
            return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED;
        }
    };
    spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l);
    spanTags.setTagMaps(manualTags);
    spanTags.setShowIcon(false);
    spanTags.updateTags();

    SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l);
    spanState.setTagMaps(stateTags);
    spanState.setShowIcon(false);
    spanState.updateTags();

    return builder.create();
}

From source file:org.inftel.ssa.mobile.ui.fragments.ProjectDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.ssa_project_details, container, false);

    Bundle arguments = getArguments();//from  w  ww .  j  a va  2 s  .  c  o  m
    if (arguments != null && arguments.get("_uri") != null) {
        mContentUri = (Uri) arguments.get("_uri");
    }

    setHasOptionsMenu(true);

    // Handle sprints click
    view.findViewById(R.id.project_btn_sprints).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(ACTION_VIEW, Projects.buildSprintsDirUri(mProjectId)));
        }
    });
    // Handle users click
    view.findViewById(R.id.project_btn_users).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(ACTION_VIEW, Projects.buildUsersDirUri(mProjectId)));
        }
    });
    // Handle tasks click
    view.findViewById(R.id.project_btn_tasks).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(ACTION_VIEW, Projects.buildTasksDirUri(mProjectId)));
        }
    });

    TabHost tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
    tabHost.setup();
    setupDescriptionTab(view);
    setupLinksTab(view);
    setupInformationTab(view);

    return view;
}

From source file:org.geometerplus.android.fbreader.bookmark.EditBookmarkActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.edit_bookmark);

    myBookmark = FBReaderIntents.getBookmarkExtra(getIntent());
    if (myBookmark == null) {
        finish();//from   w  w  w.j  a  va 2 s. c o  m
        return;
    }

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final int width = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm),
            dm.widthPixels * 9 / 10);
    final int height = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, dm),
            dm.heightPixels * 9 / 10);

    final TabHost tabHost = (TabHost) findViewById(R.id.edit_bookmark_tabhost);
    tabHost.setLayoutParams(new FrameLayout.LayoutParams(new ViewGroup.LayoutParams(width, height)));
    tabHost.setup();

    addTab(tabHost, "text", R.id.edit_bookmark_content_text);
    addTab(tabHost, "style", R.id.edit_bookmark_content_style);
    addTab(tabHost, "delete", R.id.edit_bookmark_content_delete);

    final ZLStringOption currentTabOption = new ZLStringOption("LookNFeel", "EditBookmark", "text");
    tabHost.setCurrentTabByTag(currentTabOption.getValue());
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        public void onTabChanged(String tag) {
            if (!"delete".equals(tag)) {
                currentTabOption.setValue(tag);
            }
        }
    });

    final EditText editor = (EditText) findViewById(R.id.edit_bookmark_text);
    editor.setText(myBookmark.getText());
    final int len = editor.getText().length();
    editor.setSelection(len, len);

    final Button saveTextButton = (Button) findViewById(R.id.edit_bookmark_save_text_button);
    saveTextButton.setEnabled(false);
    saveTextButton.setText(myResource.getResource("saveText").getValue());
    saveTextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {
                public void run() {
                    myBookmark.setText(editor.getText().toString());
                    myCollection.saveBookmark(myBookmark);
                    saveTextButton.setEnabled(false);
                }
            });
        }
    });
    editor.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence sequence, int start, int before, int count) {
            final String originalText = myBookmark.getText();
            saveTextButton.setEnabled(!originalText.equals(editor.getText().toString()));
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    final Button deleteButton = (Button) findViewById(R.id.edit_bookmark_delete_button);
    deleteButton.setText(myResource.getResource("deleteBookmark").getValue());
    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {
                public void run() {
                    myCollection.deleteBookmark(myBookmark);
                    finish();
                }
            });
        }
    });
}

From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.activities.MainActivity.java

private void tabSetup() {
    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);

    tabHost.setup();

    View tabView = createTabView(this, TAB_MAP);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab1").setIndicator(tabView).setContent(R.id.tabMap);
    tabHost.addTab(spec);/*from  w w  w . j  av a  2  s. c  om*/

    tabView = createTabView(this, TAB_STATISTICS);
    spec = tabHost.newTabSpec("tab2").setIndicator(tabView).setContent(R.id.tabStatistics);
    tabHost.addTab(spec);
}

From source file:net.line2soft.preambul.views.ExcursionInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    //Check if this version of Android allows to use custom title bars
    boolean feature = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    /** Set layout **/
    //Base layout
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_excursion_info);
    //set title bar
    if (feature) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_title_bar);
        TextView myTitleText = (TextView) findViewById(R.id.textView0);
        myTitleText.setText(getString(R.string.title_activity_excursion_info));
    }//from  ww w .j  a v a 2 s .  c om

    //Get excursion ID
    int id = getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0);
    if (id > 0) {
        //Set listener
        listener = new ExcursionInfoListener(this);
        //Set tabs

        TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1 = tabHost.newTabSpec("Info");
        spec1.setContent(R.id.tab1);
        spec1.setIndicator("", getResources().getDrawable(R.drawable.description_tab));
        spec1.setContent(R.id.tab1);

        TabSpec spec2 = tabHost.newTabSpec("POI");
        spec2.setIndicator("", getResources().getDrawable(R.drawable.pois_tab));
        spec2.setContent(R.id.tab2);

        TabSpec spec3 = tabHost.newTabSpec("Instructions");
        spec3.setIndicator("", getResources().getDrawable(R.drawable.instruction_tab));
        spec3.setContent(R.id.tab3);

        TabSpec spec4 = tabHost.newTabSpec("Photos");
        spec4.setIndicator("", getResources().getDrawable(R.drawable.photos_tab));
        spec4.setContent(R.id.tab4);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
        tabHost.addTab(spec4);

        //set the info tab
        try {
            Excursion exc = MapController.getInstance(this).getCurrentLocation().getExcursions(this).get(id);
            //Display locomotions
            Locomotion[] locomotionsItems = exc.getLocomotions();
            LinearLayout locomotionsLayout = (LinearLayout) findViewById(R.id.locomotionsLayout);
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            for (int i = 0; i < locomotionsItems.length; i++) {
                if (locomotionsItems[i].getIcon() == null) {
                    //Define icon if undefined
                    int imageResource = getResources().getIdentifier(
                            "locomotion_" + locomotionsItems[i].getKey(), "drawable", getPackageName());
                    if (imageResource != 0) {
                        Drawable ic = getResources().getDrawable(imageResource);
                        locomotionsItems[i].setIcon(ic);
                    }
                }
                ImageView img = (ImageView) inflater.inflate(R.layout.locomotion_item, null);
                img.setImageDrawable(locomotionsItems[i].getIcon());
                locomotionsLayout.addView(img);
            }

            int value = exc.getDifficulty();
            if (value == Excursion.DIFFICULTY_NONE) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte1);
            } else if (value == Excursion.DIFFICULTY_EASY) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte2);

            } else if (value == Excursion.DIFFICULTY_MEDIUM) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte3);

            } else if (value == Excursion.DIFFICULTY_HARD) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte4);

            } else if (value == Excursion.DIFFICULTY_EXPERT) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte5);

            }
            String time = ExcursionAdapter.convertTime(exc.getTime());

            TextView view = (TextView) findViewById(R.id.textView1);
            view.setText(time);

            Double length = Double.valueOf(exc.getLength() / 1000);
            String lengthString = length.toString().substring(0, length.toString().lastIndexOf(".") + 2)
                    + " km";
            view = (TextView) findViewById(R.id.textView2);
            view.setText(lengthString);

            view = (TextView) findViewById(R.id.textView3);
            view.setText(exc.getDescription());

        } catch (Exception e) {
            e.printStackTrace();
            onBackPressed();
            displayInfo(getString(R.string.message_excursion_not_found));
        }
        MapController exc = MapController.getInstance(this);

        //set the POI tab
        try {
            PointOfInterest[] pois = exc.getCurrentLocation().getExcursions(this).get(id)
                    .getSurroundingPois(this);
            List<NamedPoint> itemsList = Arrays.asList(((NamedPoint[]) pois));
            Collections.sort(itemsList, new NamedPointComparator());
            pois = itemsList.toArray(new PointOfInterest[itemsList.size()]);
            if (pois.length > 0) {
                ListView listPoi = (ListView) findViewById(R.id.listView2);
                listPoi.setAdapter(new FavoriteAdapter(getLayoutInflater(), pois, this));
                listPoi.setOnItemClickListener(listener);
                listPoi.setVisibility(View.VISIBLE);
                findViewById(R.id.NoPOIs).setVisibility(View.GONE);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Couldn't fill POI tab");
        }

        //set the instruction tab
        ListView list = (ListView) findViewById(R.id.listView1);
        if (list != null) {
            try {
                NavigationInstruction[] instructions = exc.getCurrentLocation().getExcursions(this).get(id)
                        .getInstructions();
                if (instructions.length != 0) {
                    ((TextView) findViewById(R.id.NoInstructions)).setVisibility(View.GONE);
                }
                list.setAdapter(new ExcursionInfoInstructionAdapter(this, instructions));
                list.setOnItemClickListener(listener);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //Set the picture tab
        String imagePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "Android"
                + File.separator + "data" + File.separator + "net.line2soft.preambul" + File.separator + "files"
                + File.separator + MapController.getInstance(this).getCurrentLocation().getId() + File.separator
                + "excursions" + File.separator
                + getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0);
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.getAbsolutePath().matches(".*\\.jpg");
            }
        };
        imagesFile = new File(imagePath).listFiles(filter);
        ((TextView) findViewById(R.id.NoPhotos)).setVisibility(View.VISIBLE);
        if (imagesFile != null) {
            if (imagesFile.length > 0) {
                ((TextView) findViewById(R.id.NoPhotos)).setVisibility(View.GONE);
                ImagePagerAdapter adapter = new ImagePagerAdapter(getSupportFragmentManager(), imagesFile,
                        this);
                ViewPager myPager = (ViewPager) findViewById(R.id.pager_images);
                myPager.setAdapter(adapter);
                myPager.setOnPageChangeListener(listener);

                //Set listener on right and left buttons in picture tab
                (findViewById(R.id.imageRight)).setOnClickListener(listener);
                (findViewById(R.id.imageLeft)).setOnClickListener(listener);
                //Change visibility of these buttons
                ImageView right = (ImageView) findViewById(R.id.imageRight);
                ImageView left = (ImageView) findViewById(R.id.imageLeft);
                left.setVisibility(View.INVISIBLE);
                right.setVisibility(View.INVISIBLE);
                int idPhoto = ((ViewPager) findViewById(R.id.pager_images)).getCurrentItem();
                int nbPhotos = getImagesFile().length;
                if (idPhoto != nbPhotos - 1) {
                    right.setVisibility(View.VISIBLE);
                }
            }
        }

        //Set listener on launch button
        Button launch = (Button) findViewById(R.id.button_load_excursion);
        launch.setOnClickListener(listener);

    } else {
        onBackPressed();
        displayInfo(getString(R.string.message_excursion_not_found));
    }
}

From source file:org.exobel.routerkeygen.ui.Preferences.java

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_ABOUT: {
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(R.id.tabhost));
        TabHost tabs = (TabHost) layout.findViewById(R.id.tabhost);
        tabs.setup();
        TabSpec tspec1 = tabs.newTabSpec("about");
        tspec1.setIndicator(getString(R.string.pref_about));

        tspec1.setContent(R.id.text_about_scroll);
        TextView text = ((TextView) layout.findViewById(R.id.text_about));
        text.setMovementMethod(LinkMovementMethod.getInstance());
        text.append(VERSION + "\n" + LAUNCH_DATE);
        tabs.addTab(tspec1);//from   w  ww.j  a v a2s. c  o  m
        TabSpec tspec2 = tabs.newTabSpec("credits");
        tspec2.setIndicator(getString(R.string.dialog_about_credits));
        tspec2.setContent(R.id.about_credits_scroll);
        ((TextView) layout.findViewById(R.id.about_credits))
                .setMovementMethod(LinkMovementMethod.getInstance());
        tabs.addTab(tspec2);
        TabSpec tspec3 = tabs.newTabSpec("license");
        tspec3.setIndicator(getString(R.string.dialog_about_license));
        tspec3.setContent(R.id.about_license_scroll);
        ((TextView) layout.findViewById(R.id.about_license))
                .setMovementMethod(LinkMovementMethod.getInstance());
        tabs.addTab(tspec3);
        builder.setNeutralButton(R.string.bt_close, new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                removeDialog(DIALOG_ABOUT);

            }
        });
        builder.setView(layout);
        break;
    }
    case DIALOG_ASK_DOWNLOAD: {
        DialogInterface.OnClickListener diOnClickListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // Check if we have the latest dictionary version.
                try {
                    checkCurrentDictionary();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        builder.setTitle(R.string.pref_download);
        builder.setMessage(R.string.msg_dicislarge);
        builder.setCancelable(false);
        builder.setPositiveButton(android.R.string.yes, diOnClickListener);
        builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                removeDialog(DIALOG_ASK_DOWNLOAD);
            }
        });
        break;
    }
    case DIALOG_UPDATE_NEEDED: {
        builder.setTitle(R.string.update_title)
                .setMessage(getString(R.string.update_message, lastVersion.version))
                .setNegativeButton(R.string.bt_close, new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        removeDialog(DIALOG_UPDATE_NEEDED);
                    }
                }).setPositiveButton(R.string.bt_website, new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(lastVersion.url)));
                    }
                });
        break;
    }
    case DIALOG_WAIT: {
        ProgressDialog pbarDialog = new ProgressDialog(Preferences.this);
        pbarDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pbarDialog.setMessage(getString(R.string.msg_wait));
        return pbarDialog;
    }
    case DIALOG_ERROR_TOO_ADVANCED: {
        builder.setTitle(R.string.msg_error).setMessage(R.string.msg_err_online_too_adv);
        break;
    }
    case DIALOG_ERROR: {
        builder.setTitle(R.string.msg_error).setMessage(R.string.msg_err_unkown);
        break;
    }
    case DIALOG_CHANGELOG: {
        LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ChangeLogListView chgList = (ChangeLogListView) layoutInflater.inflate(R.layout.dialog_changelog,
                (ViewGroup) this.getWindow().getDecorView().getRootView(), false);
        builder.setTitle(R.string.pref_changelog).setView(chgList).setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });
        break;
    }
    }
    return builder.create();
}

From source file:org.uguess.android.sysinfo.SiragonInfo.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Util.hookExceptionHandler(getApplicationContext());

    if (Util.SDK_VER < 11) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }/* w  ww.j  a va 2  s  . c  o m*/

    setContentView(R.layout.main);

    TabHost th = (TabHost) findViewById(android.R.id.tabhost);
    th.setup();

    ViewPager vp = (ViewPager) findViewById(R.id.pager);

    ITabContainer tabContainer = null;

    if (Util.SDK_VER >= 11) {
        // if ( mtdGetActionBar != null
        // && mtdSetDisplayShowTitleEnabled != null
        // && mtdSetNavigationMode != null
        // && mtdSetListNavigationCallbacks != null
        // && mtdSetSelectedNavigationItem != null )
        // {
        // try
        // {
        // Object actionBar = mtdGetActionBar.invoke( this );
        //
        // mtdSetDisplayShowTitleEnabled.invoke( actionBar, false );
        // mtdSetNavigationMode.invoke( actionBar,
        // ActionBar.NAVIGATION_MODE_LIST );
        //
        // tabContainer = new NavListAdapter( this,
        // actionBar,
        // vp,
        // new String[]{
        // getString( R.string.tab_info ),
        // getString( R.string.tab_apps ),
        // getString( R.string.tab_procs ),
        // getString( R.string.tab_netstat )
        // } );
        // }
        // catch ( Exception e )
        // {
        // Log.e( QSystemInfo.class.getName( ),
        // e.getLocalizedMessage( ),
        // e );
        // }
        // }
    }

    if (tabContainer == null) {
        tabContainer = new TabsAdapter(this, th, vp);
    }

    tabContainer.addTab(th.newTabSpec(SiragonManager.class.getName()).setIndicator(getString(R.string.tab_info),
            getResources().getDrawable(R.drawable.info)), SiragonManager.class, null);

    tabContainer.addTab(th.newTabSpec(ApplicationManager.class.getName())
            .setIndicator(getString(R.string.tab_apps), getResources().getDrawable(R.drawable.applications)),
            ApplicationManager.class, null);

    tabContainer.addTab(th.newTabSpec(ProcessManager.class.getName())
            .setIndicator(getString(R.string.tab_procs), getResources().getDrawable(R.drawable.processes)),
            ProcessManager.class, null);

    tabContainer.addTab(th.newTabSpec(NetStateManager.class.getName())
            .setIndicator(getString(R.string.tab_netstat), getResources().getDrawable(R.drawable.connection)),
            NetStateManager.class, null);

    SharedPreferences sp = getSharedPreferences(SiragonManager.PSTORE_SYSINFOMANAGER, Context.MODE_PRIVATE);

    fixTextView(th);

    Util.updateIcons(this, sp);

    if (sp != null) {
        int tab = sp.getInt(SiragonManager.PREF_KEY_DEFAULT_TAB, 0);

        if (tab == 0) {
            tab = sp.getInt(PREF_KEY_LAST_ACTIVE, 1);
        }

        if (tab > 0 && tab < 5) {
            th.setCurrentTab(tab - 1);
        }
    }
}

From source file:com.tutor.fragment.ViewPageFragment.java

private void initialMainTabHost(LayoutInflater inflater, View mView) {

    View sgTab = inflater.inflate(R.layout.tab_main_widebg, null);
    TextView sgtv = (TextView) sgTab.findViewById(R.id.mainTabTv);
    sgtv.setText("3G");

    View yxTab = inflater.inflate(R.layout.tab_main_widebg, null);
    TextView yxtv = (TextView) yxTab.findViewById(R.id.mainTabTv);
    yxtv.setText("");
    TabHost yxTabHost = (TabHost) mView.findViewById(R.id.yxTabHost);
    yxTabHost.setup();
    yxTabHost.addTab(yxTabHost.newTabSpec("3GTab").setIndicator(sgTab).setContent(R.id.tab_3gfudao));
    yxTabHost.addTab(yxTabHost.newTabSpec("YXJifen").setIndicator(yxTab).setContent(R.id.tab_yxjifen));
    yxTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override//  w  w  w .  j a v a2 s. c  o m
        public void onTabChanged(String tabId) {
            if (tabId.equals("3GTab")) {
                // ListView myTabLst = (ListView)
                // findViewById(R.id.myTabLst);

            } else {

            }
        }

    });
}