Example usage for android.widget LinearLayout findViewById

List of usage examples for android.widget LinearLayout findViewById

Introduction

In this page you can find the example usage for android.widget LinearLayout findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:com.saulcintero.moveon.fragments.Summary2.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity().getApplicationContext();

    prefs = PreferenceManager.getDefaultSharedPreferences(mContext);

    LinearLayout fragmentView = (LinearLayout) inflater.inflate(R.layout.summary2, container, false);
    summary2ListView = (ListView) fragmentView.findViewById(R.id.summary2_list_splitlaps);
    summary2ListView.setSelector(android.R.color.transparent);
    label1 = (TextView) fragmentView.findViewById(R.id.summary2_item_one);
    label2 = (TextView) fragmentView.findViewById(R.id.summary2_label_one);

    isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext);

    unit = (isMetric ? 1000 : 1609);/*from   w  w w .  ja  va  2 s. c o m*/

    label1.setText((isMetric ? getString(R.string.long_unit1_detail_1).toUpperCase(Locale.getDefault())
            : getString(R.string.long_unit2_detail_1).toUpperCase(Locale.getDefault())) + ".");
    label2.setText("1 " + (isMetric ? getString(R.string.long_unit1_detail_1).toUpperCase(Locale.getDefault())
            : getString(R.string.long_unit2_detail_1).toUpperCase(Locale.getDefault())) + ".");

    seekBar = (SeekBar) fragmentView.findViewById(R.id.summary2_slider);
    seekBar.setMax(49);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            splitData(progress * unit);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progr, boolean fromUser) {
            progress = progr + 1;

            label2.setText(String.valueOf(progress) + " "
                    + (isMetric ? getString(R.string.long_unit1_detail_1).toUpperCase(Locale.getDefault())
                            : getString(R.string.long_unit2_detail_1).toUpperCase(Locale.getDefault()))
                    + ".");
        }
    });

    return fragmentView;
}

From source file:com.partypoker.poker.engagement.reach.activity.EngagementPollActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    /* Init layout */
    super.onCreate(savedInstanceState);

    /* If no content, nothing to do, super class already called finish */
    if (mContent == null)
        return;/*from  w  w w .j  a  va2 s  . c om*/

    /* Render questions */
    LinearLayout questionsLayout = getView("questions");
    JSONArray questions = mContent.getQuestions();
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    try {
        for (int i = 0; i < questions.length(); i++) {
            /* Get question */
            JSONObject question = questions.getJSONObject(i);

            /* Inflate question layout */
            LinearLayout questionLayout = (LinearLayout) layoutInflater
                    .inflate(getLayoutId("engagement_poll_question"), null);

            /* Set question's title */
            TextView questionTitle = (TextView) questionLayout.findViewById(getId("question_title"));
            questionTitle.setText(question.getString("title"));

            /* Set choices */
            RadioGroup choicesView = (RadioGroup) questionLayout.findViewById(getId("choices"));
            choicesView.setTag(question);
            JSONArray choices = question.getJSONArray("choices");
            int choiceViewId = 0;
            for (int j = 0; j < choices.length(); j++) {
                /* Get choice */
                JSONObject choice = choices.getJSONObject(j);

                /* Inflate choice layout */
                RadioButton choiceView = (RadioButton) layoutInflater
                        .inflate(getLayoutId("engagement_poll_choice"), null);

                /* Each choice is a radio button */
                choiceView.setId(choiceViewId++);
                choiceView.setTag(choice.getString("id"));
                choiceView.setText(choice.getString("title"));
                choiceView.setChecked(choice.optBoolean("isDefault"));
                choicesView.addView(choiceView);
            }

            /* Add to parent layouts */
            questionsLayout.addView(questionLayout);

            /* Watch state */
            mRadioGroups.add(choicesView);
            choicesView.setOnCheckedChangeListener(mRadioGroupListener);
        }
    } catch (JSONException jsone) {
        /* Drop on parsing error */
        mContent.dropContent(this);
        finish();
        return;
    }

    /* Disable action if a choice is not selected */
    updateActionState();
}

From source file:com.orange.essentials.otb.ui.OtbTermsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.otb_terms, container, false);
    LinearLayout llayout = (LinearLayout) mView.findViewById(R.id.otb_terms_layout);
    TextView headerTv = (TextView) llayout.findViewById(R.id.otb_header_tv_text);
    headerTv.setText(R.string.otb_home_terms_content);
    List<Term> terms = TrustBadgeManager.INSTANCE.getTerms();

    for (Term term : terms) {
        View layoutToAdd = null;//from  w w w .j  a v a 2 s. c  o  m
        if (term.getTermType() == TermType.VIDEO
                && Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
            layoutToAdd = View.inflate(getActivity(), R.layout.otb_terms_video, null);
            TextView titleTv = (TextView) layoutToAdd.findViewById(R.id.otb_term_video_title);
            final AutoResizingFrameLayout anchorView = (AutoResizingFrameLayout) layoutToAdd
                    .findViewById(R.id.videoSurfaceContainer);
            if (mVideoViews == null) {
                mVideoViews = new ArrayList<>();
            }
            mVideoViews.add(anchorView);
            SurfaceView videoSurface = (SurfaceView) layoutToAdd.findViewById(R.id.videoSurface);

            titleTv.setText(term.getTitleId());

            SurfaceHolder videoHolder = videoSurface.getHolder();
            MediaPlayer player = new MediaPlayer();
            if (mPlayers == null) {
                mPlayers = new ArrayList<>();
            }
            mPlayers.add(player);
            final VideoControllerView controller = new VideoControllerView(getContext());
            VideoCallback videoCallback = new VideoCallback(player, controller, anchorView);
            videoHolder.addCallback(videoCallback);
            anchorView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    controller.show();
                    return false;
                }
            });
            try {
                player.setAudioStreamType(AudioManager.STREAM_MUSIC);
                player.setDataSource(getContext(), Uri.parse(getString(term.getContentId())));
                player.setOnPreparedListener(videoCallback);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (term.getTermType() == TermType.TEXT) {//TermType.TEXT
            layoutToAdd = View.inflate(getActivity(), R.layout.otb_terms_text, null);
            TextView titleTv = (TextView) layoutToAdd.findViewById(R.id.otb_term_text_title);
            TextView contentTv = (TextView) layoutToAdd.findViewById(R.id.otb_term_text_content);
            titleTv.setText(term.getTitleId());
            contentTv.setText(Html.fromHtml(getString(term.getContentId())));
            contentTv.setMovementMethod(LinkMovementMethod.getInstance());
            contentTv.setLinkTextColor(getResources().getColor(R.color.colorAccent));
        }
        if (null != layoutToAdd) {
            llayout.addView(layoutToAdd);
        }
        if (terms.indexOf(term) != terms.size() - 1) {
            View.inflate(getActivity(), R.layout.otb_separator, llayout);
        }
    }

    return mView;
}

From source file:dynamite.zafroshops.app.fragment.ZopItemFragment.java

private void setLayout(LayoutInflater inflater, LinearLayout layout, final FullMobileZop zop,
        RelativeLayout loader) {/*from  ww  w .ja v  a  2s . co m*/
    LinearLayout item = (LinearLayout) layout.findViewById(R.id.itemZop);

    loader.setVisibility(View.VISIBLE);
    item.setVisibility(View.INVISIBLE);
    if (zop != null && zop.id != null && !zop.id.trim().equals("")) {
        MainActivity activity = (MainActivity) getActivity();
        (activity).setCurrentItem(zop.id, zop);

        LinearLayout list = (LinearLayout) layout.findViewById(R.id.zopOpeningHours);
        ArrayList<MobileOpeningHourData> ohs = zop.getGroupedOpeningHours();

        // set other fields
        ((ImageView) item.findViewById(R.id.zopImg)).setImageResource(R.drawable.nopictureyet);
        ((TextView) item.findViewById(R.id.zopName)).setText(zop.Name);
        ((TextView) item.findViewById(R.id.zopStreet)).setText(zop.Street + " " + zop.StreetNumber);
        ((TextView) item.findViewById(R.id.zopCity)).setText(zop.City);
        ((TextView) item.findViewById(R.id.zopCountry)).setText(zop.CountryName);

        LinearLayout linearLayout = ((LinearLayout) item.findViewById(R.id.zopServiceIcons));

        linearLayout.removeAllViews();
        setView(zop.Type.toString(), zop.Type.getText(), linearLayout, inflater);
        for (Object s : zop.Services) {
            ZopServiceType zopServiceType = ((MobileZopService) s).Service;

            if (!zopServiceType.toString().equals(zop.Type.toString())) {
                setView(zopServiceType.toString(), zopServiceType.getText(), linearLayout, inflater);
            }
        }

        if (zop.Distance > 0) {
            ((TextView) item.findViewById(R.id.locatoin_km)).setText(
                    " (" + String.format("%.0f", zop.Distance) + " " + getString(R.string.far_away) + ")");
        }
        if (zop.PhoneNumber == null || zop.PhoneNumber.trim().equals("")) {
            item.findViewById(R.id.zopPhoneNumberLabel).setVisibility(View.INVISIBLE);
        } else {
            item.findViewById(R.id.zopPhoneNumberLabel).setVisibility(View.VISIBLE);
            ((TextView) item.findViewById(R.id.zopPhoneNumber))
                    .setText(zop.CountryPhoneCode + " " + zop.PhoneNumber);
        }

        if (zop.Details == null || zop.Details.trim().equals("")) {
            item.findViewById(R.id.zopDetailsLabel).setVisibility(View.INVISIBLE);
        } else {
            item.findViewById(R.id.zopDetailsLabel).setVisibility(View.VISIBLE);
            ((TextView) item.findViewById(R.id.zopDetails)).setText(zop.Details);
        }
        // set opening hours
        setOpeningsList(ohs, list, inflater, (TextView) item.findViewById(R.id.zopOpeningHoursLabel));
        loader.setVisibility(View.INVISIBLE);
        item.setVisibility(View.VISIBLE);
    }
}

From source file:com.androguide.honamicontrol.fragments.WelcomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.cardsui, container, false);
    final ActionBarActivity fa = (ActionBarActivity) super.getActivity();
    fa.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    fa.getSupportActionBar().setHomeButtonEnabled(true);

    assert ll != null;
    CardUI mCardUI = (CardUI) (ll.findViewById(R.id.cardsui));
    ArrayList<Card> mCards = new ArrayList<Card>();

    mCardUI.addStack(new CardStack(""));

    mCards.add(new CardCategory(fa.getString(R.string.kernel_control),
            fa.getString(R.string.kernel_control_desc), "#16a085", "", false));

    mCards.add(new CardCategory(fa.getString(R.string.sound_control), fa.getString(R.string.sound_control_desc),
            fa.getString(R.string.sound_control_color), "", false));

    mCards.add(new CardCategory(fa.getString(R.string.touch_screen), fa.getString(R.string.touch_screen_desc),
            fa.getString(R.string.touch_screen_color), "", false));

    mCards.add(new CardCategory(fa.getString(R.string.help_center),
            fa.getString(R.string.help_center_introduction), fa.getString(R.string.help_center_color), "",
            false));//  w  w w.j a v  a  2 s. c om

    for (int i = 0; i < mCards.size(); i++) {
        final int curr = i + 1;
        Card card = mCards.get(i);
        card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.getViewPager().setCurrentItem(curr, true);
            }
        });
        mCardUI.addCard(card);
    }

    mCardUI.addStack(new CardStack());
    mCardUI.refresh();
    return ll;
}

From source file:com.example.android.scopeddirectoryaccess.ScopedDirectoryAccessFragment.java

@Override
public void onViewCreated(final View rootView, Bundle savedInstanceState) {
    super.onViewCreated(rootView, savedInstanceState);

    mCurrentDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_current_directory);
    mNothingInDirectoryTextView = (TextView) rootView.findViewById(R.id.textview_nothing_in_directory);
    mPrimaryVolumeNameTextView = (TextView) rootView.findViewById(R.id.textview_primary_volume_name);

    // Set onClickListener for the primary volume
    Button openPictureButton = (Button) rootView.findViewById(R.id.button_open_directory_primary_volume);
    openPictureButton.setOnClickListener(new View.OnClickListener() {
        @Override/*w  w w. ja va 2s.  c o m*/
        public void onClick(View view) {
            String selected = mDirectoriesSpinner.getSelectedItem().toString();
            String directoryName = getDirectoryName(selected);
            StorageVolume storageVolume = mStorageManager.getPrimaryStorageVolume();
            Intent intent = storageVolume.createAccessIntent(directoryName);
            startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE);
        }
    });

    // Set onClickListener for the external volumes if exists
    List<StorageVolume> storageVolumes = mStorageManager.getStorageVolumes();
    LinearLayout containerVolumes = (LinearLayout) mActivity.findViewById(R.id.container_volumes);
    for (final StorageVolume volume : storageVolumes) {
        String volumeDescription = volume.getDescription(mActivity);
        if (volume.isPrimary()) {
            // Primary volume area is already added...
            if (volumeDescription != null) {
                // ...but with a default name: set it to the real name when available.
                mPrimaryVolumeNameTextView.setText(volumeDescription);
            }
            continue;
        }
        LinearLayout volumeArea = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.volume_entry,
                containerVolumes);
        TextView volumeName = (TextView) volumeArea.findViewById(R.id.textview_volume_name);
        volumeName.setText(volumeDescription);
        Button button = (Button) volumeArea.findViewById(R.id.button_open_directory);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String selected = mDirectoriesSpinner.getSelectedItem().toString();
                String directoryName = getDirectoryName(selected);
                Intent intent = volume.createAccessIntent(directoryName);
                startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE);
            }
        });
    }
    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview_directory_entries);
    if (savedInstanceState != null) {
        mDirectoryEntries = savedInstanceState.getParcelableArrayList(DIRECTORY_ENTRIES_KEY);
        mCurrentDirectoryTextView.setText(savedInstanceState.getString(SELECTED_DIRECTORY_KEY));
        mAdapter = new DirectoryEntryAdapter(mDirectoryEntries);
        if (mAdapter.getItemCount() == 0) {
            mNothingInDirectoryTextView.setVisibility(View.VISIBLE);
        }
    } else {
        mDirectoryEntries = new ArrayList<>();
        mAdapter = new DirectoryEntryAdapter();
    }
    recyclerView.setAdapter(mAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mDirectoriesSpinner = (Spinner) rootView.findViewById(R.id.spinner_directories);
    ArrayAdapter<CharSequence> directoriesAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.directories, android.R.layout.simple_spinner_item);
    directoriesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mDirectoriesSpinner.setAdapter(directoriesAdapter);
}

From source file:com.sonymobile.android.media.testmediaplayer.filebrowsing.MediaBrowser.java

private void init() {
    mListDataHeader = new ArrayList<String>();
    mListDataChild = new HashMap<String, List<MediaSource>>();
    mAllSources = new HashMap<String, HashMap<String, String>>();
    readFromMediaStore();/*  w  w w  .  ja va  2  s . c  o  m*/
    readFileFromPath(null);
    readFileFromPath(Environment.getExternalStorageDirectory() + "/demoapplication_links.txt");
    prepareListData();

    mDebugTitle = (TextView) mDebugLayout.findViewById(R.id.activity_main_debug_media_title);

    mlistAdapter = new ExpandableListViewAdapter(mContext, mListDataHeader, mListDataChild);
    mExpandableListView.setAdapter(mlistAdapter);
    mExpandableListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            LinearLayout layout = (LinearLayout) v;
            TextView tv = (TextView) layout.findViewById(R.id.expand_list_item);
            mDebugTitle.setText(mListDataHeader.get(groupPosition) + " / " + tv.getText());
            if (groupPosition == 0 && mListDataHeader.get(groupPosition).equals("Local files")) {
                startMediaPlayer(mAllSources.get(mListDataHeader.get(groupPosition)).get(tv.getText()), true);
            } else {
                startMediaPlayer(mAllSources.get(mListDataHeader.get(groupPosition)).get(tv.getText()), false);

            }
            return false;
        }

    });
}

From source file:com.achep.base.ui.DialogBuilder.java

private View createSkeleton() {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout rootLayout = (LinearLayout) inflater.inflate(R.layout.dialog_main_skeleton,
            new FrameLayout(mContext), false);
    TextView titleView = (TextView) rootLayout.findViewById(R.id.title);

    if (Device.hasLollipopApi()) {
        // The dividers are quite ugly with material design.
        rootLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }//from w w w. j av a  2s . c  o m

    if (mTitleText == null && mIcon == null) {
        rootLayout.removeView(titleView);
    } else {
        if (mTitleText != null)
            titleView.setText(mTitleText);
        if (mIcon != null)
            titleView.setCompoundDrawablesWithIntrinsicBounds(mIcon, null, null, null);
    }

    return rootLayout;
}

From source file:com.kaixin.android.service.UpdateApp.java

public void Beginning() {
    LinearLayout ll = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.layout_progress, null);
    mProgressBar = (ProgressBar) ll.findViewById(R.id.down_pb);
    mDownloadTxt = (TextView) ll.findViewById(R.id.download_txt);
    Builder builder = new Builder(context);
    builder.setView(ll);/*from  www. ja  v  a 2s . co m*/
    builder.setTitle(context.getString(R.string.update_load_txt));
    builder.setNegativeButton(context.getString(R.string.update_hide_txt),
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(context, UpdateService.class);
                    context.startService(intent);
                    dialog.dismiss();
                }
            });
    builder.show();

    new Thread() {
        public void run() {
            loadFile(DOWNLOAD_URL);
        }
    }.start();
}

From source file:com.android.gallery3d.filtershow.category.CategoryPanel.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout main = (LinearLayout) inflater.inflate(R.layout.filtershow_category_panel_new, container,
            false);// w w  w  .j a v  a2  s.c o m

    if (savedInstanceState != null) {
        int selectedPanel = savedInstanceState.getInt(PARAMETER_TAG);
        loadAdapter(selectedPanel);
    }

    View panelView = main.findViewById(R.id.listItems);
    if (panelView instanceof CategoryTrack) {
        CategoryTrack panel = (CategoryTrack) panelView;
        if (mAdapter != null) {
            mAdapter.setOrientation(CategoryView.HORIZONTAL);
            panel.setAdapter(mAdapter);
            mAdapter.setContainer(panel);
        }
    } else if (mAdapter != null) {
        ListView panel = (ListView) main.findViewById(R.id.listItems);
        panel.setAdapter(mAdapter);
        mAdapter.setContainer(panel);
    }

    mAddButton = (IconView) main.findViewById(R.id.addButton);
    if (mAddButton != null) {
        mAddButton.setOnClickListener(this);
        updateAddButtonVisibility();
    }
    return main;
}