Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.gh4a.fragment.UserFragment.java

public void fillTopRepos(Collection<Repository> topRepos) {
    LinearLayout ll = (LinearLayout) mContentView.findViewById(R.id.ll_top_repos);
    ll.removeAllViews();// w  w w .j av a 2  s .  c  o  m

    LayoutInflater inflater = getLayoutInflater(null);

    if (topRepos != null) {
        for (Repository repo : topRepos) {
            View rowView = inflater.inflate(R.layout.top_repo, null);
            rowView.setOnClickListener(this);
            rowView.setTag(repo);

            TextView tvTitle = (TextView) rowView.findViewById(R.id.tv_title);
            tvTitle.setText(repo.getOwner().getLogin() + "/" + repo.getName());

            TextView tvDesc = (TextView) rowView.findViewById(R.id.tv_desc);
            if (!StringUtils.isBlank(repo.getDescription())) {
                tvDesc.setVisibility(View.VISIBLE);
                tvDesc.setText(repo.getDescription());
            } else {
                tvDesc.setVisibility(View.GONE);
            }

            TextView tvForks = (TextView) rowView.findViewById(R.id.tv_forks);
            tvForks.setText(String.valueOf(repo.getForks()));

            TextView tvStars = (TextView) rowView.findViewById(R.id.tv_stars);
            tvStars.setText(String.valueOf(repo.getWatchers()));

            ll.addView(rowView);
        }
    }

    View btnMore = getView().findViewById(R.id.btn_repos);
    if (topRepos != null && !topRepos.isEmpty()) {
        btnMore.setOnClickListener(this);
        btnMore.setVisibility(View.VISIBLE);
    } else {
        TextView hintView = (TextView) inflater.inflate(R.layout.hint_view, ll, false);
        hintView.setText(R.string.user_no_repos);
        ll.addView(hintView);
    }

    getView().findViewById(R.id.pb_top_repos).setVisibility(View.GONE);
    getView().findViewById(R.id.ll_top_repos).setVisibility(View.VISIBLE);
}

From source file:com.mediaexplorer.remote.MexRemoteActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from   ww w .  ja  v a 2 s  .  co  m

    this.setTitle(R.string.app_name);
    dbg = "MexWebremote";

    text_view = (TextView) findViewById(R.id.text);

    web_view = (WebView) findViewById(R.id.link_view);
    web_view.getSettings().setJavaScriptEnabled(true);/*
                                                      /* Future: setOverScrollMode is API level >8
                                                      * web_view.setOverScrollMode (OVER_SCROLL_NEVER);
                                                      */

    web_view.setBackgroundColor(0);

    web_view.setWebViewClient(new WebViewClient() {
        /* for some reason we only get critical errors so an auth error
         * is not handled here which is why there is some crack that test
         * the connection with a special httpclient
         */
        @Override
        public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler,
                final String host, final String realm) {
            String[] userpass = new String[2];

            userpass = view.getHttpAuthUsernamePassword(host, realm);

            HttpResponse response = null;
            HttpGet httpget;
            DefaultHttpClient httpclient;
            String target_host;
            int target_port;

            target_host = MexRemoteActivity.this.target_host;
            target_port = MexRemoteActivity.this.target_port;

            /* We may get null from getHttpAuthUsernamePassword which will
             * break the setCredentials so junk used instead to keep
             * it happy.
             */

            Log.d(dbg, "using the set httpauth, testing auth using client");
            try {
                if (userpass == null) {
                    userpass = new String[2];
                    userpass[0] = "none";
                    userpass[1] = "none";
                }
            } catch (Exception e) {
                userpass = new String[2];
                userpass[0] = "none";
                userpass[1] = "none";
            }

            /* Log.d ("debug",
             *  "trying: GET http://"+userpass[0]+":"+userpass[1]+"@"+target_host+":"+target_port+"/");
             */
            /* We're going to test the authentication credentials that we
             * have before using them so that we can act on the response.
             */

            httpclient = new DefaultHttpClient();

            httpget = new HttpGet("http://" + target_host + ":" + target_port + "/");

            httpclient.getCredentialsProvider().setCredentials(new AuthScope(target_host, target_port),
                    new UsernamePasswordCredentials(userpass[0], userpass[1]));

            try {
                response = httpclient.execute(httpget);
            } catch (IOException e) {
                Log.d(dbg, "Problem executing the http get");
                e.printStackTrace();
            }

            Log.d(dbg, "HTTP reponse:" + Integer.toString(response.getStatusLine().getStatusCode()));
            if (response.getStatusLine().getStatusCode() == 401) {
                /* We got Authentication failed (401) so ask user for u/p */

                /* login dialog box */
                final AlertDialog.Builder logindialog;
                final EditText user;
                final EditText pass;

                LinearLayout layout;
                LayoutParams params;

                TextView label_username;
                TextView label_password;

                logindialog = new AlertDialog.Builder(MexRemoteActivity.this);

                logindialog.setTitle("Mex Webremote login");

                user = new EditText(MexRemoteActivity.this);
                pass = new EditText(MexRemoteActivity.this);

                layout = new LinearLayout(MexRemoteActivity.this);

                pass.setTransformationMethod(new PasswordTransformationMethod());

                layout.setOrientation(LinearLayout.VERTICAL);

                params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

                layout.setLayoutParams(params);
                user.setLayoutParams(params);
                pass.setLayoutParams(params);

                label_username = new TextView(MexRemoteActivity.this);
                label_password = new TextView(MexRemoteActivity.this);

                label_username.setText("Username:");
                label_password.setText("Password:");

                layout.addView(label_username);
                layout.addView(user);
                layout.addView(label_password);
                layout.addView(pass);
                logindialog.setView(layout);

                logindialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                    }
                });

                logindialog.setPositiveButton("Login", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String uvalue = user.getText().toString().trim();
                        String pvalue = pass.getText().toString().trim();
                        view.setHttpAuthUsernamePassword(host, realm, uvalue, pvalue);

                        handler.proceed(uvalue, pvalue);
                    }
                });
                logindialog.show();
                /* End login dialog box */
            } else /* We didn't get a 401 */
            {
                handler.proceed(userpass[0], userpass[1]);
            }
        } /* End onReceivedHttpAuthRequest */
    }); /* End Override */

    /* Run mdns to check for service in a "runnable" (async) */
    handler.post(new Runnable() {
        public void run() {
            startMdns();
        }
    });

    dialog = ProgressDialog.show(MexRemoteActivity.this, "", "Searching...", true);

    /* Let's put something in the webview while we're waiting */
    String summary = "<html><head><style>body { background-color: #000000; color: #ffffff; }></style></head><body><p>Searching for the media explorer webservice</p><p>More infomation on <a href=\"http://media-explorer.github.com\" >Media Explorer's home page</a></p></body></html>";
    web_view.loadData(summary, "text/html", "utf-8");

}

From source file:com.i2max.i2smartwork.common.work.WorkDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {
    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || filesList.size() <= 0) {
        targetLayout.setVisibility(View.GONE);
    } else {/*from w  w w  .j  a  v  a2  s .c om*/
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = null;
                    if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                        //i2viewer ? ( conv_yn='Y')
                        intent = IntentUtil.getI2ViewerIntent(
                                FormatUtil.getStringValidate(fileMap.get("file_id")),
                                FormatUtil.getStringValidate(fileMap.get("file_nm")));
                        getActivity().startActivity(intent);
                    } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                            || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                        intent = IntentUtil.getVideoPlayIntent(downloadURL);
                    } else {
                        //? ??
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                        Bundle bundle = new Bundle();
                        bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                        intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                        Log.d(TAG, "intent:" + intent.toString());
                    }
                    getActivity().startActivity(intent);

                }
            });

            targetLayout.addView(fileView);
        }

    }
}

From source file:com.brq.wallet.activity.modern.AccountsFragment.java

private LinearLayout createActiveAccountBalanceSumView(CurrencySum spendableBalance) {
    LinearLayout outer = new LinearLayout(getActivity());
    outer.setOrientation(LinearLayout.VERTICAL);
    outer.setLayoutParams(_outerLayoutParameters);

    LinearLayout inner = new LinearLayout(getActivity());
    inner.setOrientation(LinearLayout.VERTICAL);
    inner.setLayoutParams(_innerLayoutParameters);
    inner.requestLayout();//from  www.  jav a 2 s.c o m

    // Add records
    RecordRowBuilder builder = new RecordRowBuilder(_mbwManager, getResources(), _layoutInflater);

    // Add item
    View item = builder.buildTotalView(outer, spendableBalance);
    inner.addView(item);

    // Add separator
    inner.addView(createSeparator());

    outer.addView(inner);
    return outer;
}

From source file:com.brq.wallet.activity.modern.AccountsFragment.java

private LinearLayout createAccountViewList(String title, List<WalletAccount> accounts,
        WalletAccount selectedAccount, CurrencySum spendableBalance) {
    LinearLayout outer = new LinearLayout(getActivity());
    outer.setOrientation(LinearLayout.VERTICAL);
    outer.setLayoutParams(_outerLayoutParameters);

    // Add title/*from  w ww.jav a  2 s .co  m*/
    createTitle(outer, title, spendableBalance);

    if (accounts.isEmpty()) {
        return outer;
    }

    LinearLayout inner = new LinearLayout(getActivity());
    inner.setOrientation(LinearLayout.VERTICAL);
    inner.setLayoutParams(_innerLayoutParameters);
    inner.requestLayout();

    //      // Add records
    RecordRowBuilder builder = new RecordRowBuilder(_mbwManager, getResources(), _layoutInflater);
    for (WalletAccount account : accounts) {
        // Add separator
        inner.addView(createSeparator());

        // Add item
        boolean isSelected = account.equals(selectedAccount);
        View item = createAccountView(outer, account, isSelected, builder);
        inner.addView(item);
    }

    if (accounts.size() > 0) {
        // Add separator
        inner.addView(createSeparator());
    }

    outer.addView(inner);
    return outer;
}

From source file:com.hybris.mobile.adapter.FormAdapter.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//  ww w  . ja v a 2 s.co  m
public View getView(final int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.form_row, parent, false);

    LinearLayout lnr = (LinearLayout) rowView.findViewById(R.id.linear_layout_form);
    final Hashtable<String, Object> obj = (Hashtable<String, Object>) objects.get(position);

    String className = "com.hybris.mobile.view." + obj.get("cellIdentifier").toString();
    Object someObj = null;
    try {
        Class cell;

        cell = Class.forName(className);

        Constructor constructor = cell.getConstructor(new Class[] { Context.class });
        someObj = constructor.newInstance(this.context);
    } catch (Exception e) {
        LoggingUtils.e(LOG_TAG, "Error loading class \"" + className + "\". " + e.getLocalizedMessage(),
                Hybris.getAppContext());
    }
    /*
     * Text Cell
     */

    if (someObj != null && someObj instanceof HYFormTextEntryCell) {

        final HYFormTextEntryCell textCell = (HYFormTextEntryCell) someObj;

        if (isLastEditText(position)) {
            textCell.setImeDone(this);
        }

        lnr.addView(textCell);

        textCell.setId(position);
        if (obj.containsKey("inputType")) {
            Integer val = mInputTypes.get(obj.get("inputType").toString());
            textCell.setContentInputType(val);
        }
        if (obj.containsKey("value")) {
            textCell.setContentText(obj.get("value").toString());
        }

        if (obj.containsKey("keyboardType")
                && StringUtils.equals(obj.get("keyboardType").toString(), "UIKeyboardTypeEmailAddress")) {
            textCell.setContentInputType(mInputTypes.get("textEmailAddress"));
        }

        textCell.addContentChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

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

            @Override
            public void afterTextChanged(Editable s) {
                obj.put("value", s.toString());
                notifyFormDataChangedListner();
            }
        });
        textCell.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    textCell.setTextColor(context.getResources().getColor(R.color.textMedium));
                    if (!fieldIsValid(position)) {
                        setIsValid(false);
                        textCell.showMessage(true);
                    } else {
                        textCell.showMessage(false);
                    }
                    showInvalidField();
                    validateAllFields();
                } else {
                    textCell.setTextColor(context.getResources().getColor(R.color.textHighlighted));
                    setCurrentFocusIndex(position);
                }
            }
        });

        textCell.setContentTitle(obj.get("title").toString());
        if (obj.containsKey("error")) {
            textCell.setMessage(obj.get("error").toString());
        }

        if (obj.containsKey("showerror")) {
            Boolean showerror = Boolean.parseBoolean(obj.get("showerror").toString());
            textCell.showMessage(showerror);
        } else {
            textCell.showMessage(false);
        }

        if (currentFocusIndex == position) {
            textCell.setFocus();
        }
    }
    /*
     * Secure Text Cell
     */

    else if (someObj instanceof HYFormSecureTextEntryCell) {
        final HYFormSecureTextEntryCell secureTextCell = (HYFormSecureTextEntryCell) someObj;

        if (isLastEditText(position)) {
            secureTextCell.setImeDone(this);
        }
        lnr.addView(secureTextCell);

        secureTextCell.setId(position);
        if (obj.containsKey("value")) {
            secureTextCell.setContentText(obj.get("value").toString());
        }
        if (obj.containsKey("inputType")) {
            Integer val = mInputTypes.get(obj.get("inputType").toString());
            secureTextCell.setContentInputType(val);
        }
        secureTextCell.addContentChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

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

            @Override
            public void afterTextChanged(Editable s) {
                obj.put("value", s.toString());
                notifyFormDataChangedListner();
            }

        });
        secureTextCell.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    if (!fieldIsValid(position)) {
                        setIsValid(false);
                        secureTextCell.showMessage(true);
                    } else {
                        secureTextCell.showMessage(false);
                    }
                    showInvalidField();
                    validateAllFields();
                } else {
                    setCurrentFocusIndex(position);
                }
            }
        });

        secureTextCell.setContentTitle(obj.get("title").toString());
        if (obj.containsKey("error")) {
            secureTextCell.setMessage(obj.get("error").toString());
        }

        if (obj.containsKey("showerror")) {
            Boolean showerror = Boolean.parseBoolean(obj.get("showerror").toString());
            secureTextCell.showMessage(showerror);
        } else {
            secureTextCell.showMessage(false);
        }

        if (currentFocusIndex == position) {
            secureTextCell.setFocus();
        }
    } else if (someObj instanceof HYFormTextSelectionCell) {

        setIsValid(fieldIsValid(position));

        HYFormTextSelectionCell selectionTextCell = (HYFormTextSelectionCell) someObj;
        lnr.addView(selectionTextCell);

        if (StringUtils.isNotBlank((String) obj.get("value"))) {
            StringBuilder b = new StringBuilder(obj.get("value").toString());
            selectionTextCell.setSpinnerText(b.replace(0, 1, b.substring(0, 1).toUpperCase()).toString());
        } else {
            selectionTextCell.setSpinnerText(obj.get("title").toString());
        }
    } else if (someObj instanceof HYFormTextSelectionCell2) {
        HYFormTextSelectionCell2 selectionTextCell = (HYFormTextSelectionCell2) someObj;
        lnr.addView(selectionTextCell);
        selectionTextCell.init(obj);
    } else if (someObj instanceof HYFormSwitchCell) {
        HYFormSwitchCell checkBox = (HYFormSwitchCell) someObj;
        lnr.addView(checkBox);
        checkBox.setCheckboxText(obj.get("title").toString());
        if (StringUtils.isNotBlank((String) obj.get("value"))) {
            checkBox.setCheckboxChecked(Boolean.parseBoolean((String) obj.get("value")));
        }

        checkBox.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                HYFormSwitchCell chk = (HYFormSwitchCell) v;
                chk.toggleCheckbox();
                obj.put("value", String.valueOf(chk.isCheckboxChecked()));
                notifyFormDataChangedListner();
            }
        });
    } else if (someObj instanceof HYFormSubmitButton) {
        HYFormSubmitButton btnCell = (HYFormSubmitButton) someObj;
        lnr.addView(btnCell);
        btnCell.setButtonText(obj.get("title").toString());
        btnCell.setOnButtonClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                submit();
            }
        });
    }

    return rowView;
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void combineTrainAndPsnDetails() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();/*from ww w .j a v a 2s .com*/
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        return;
    }
    //Combine both Train & Passenger details table into a single LinearLayout and add it to FrameLayout
    LinearLayout ll = new LinearLayout(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    TextView textViewPsnDtls = new TextView(mActivity);

    textViewTrnDtls.setText("Train Details: " + mPNRNumber);
    textViewTrnDtls.setFocusable(true);
    textViewPsnDtls.setText("Passenger Details");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewPsnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    textViewPsnDtls.setPadding(10, 10, 10, 10);
    textViewTrnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    textViewPsnDtls.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);
    ll.addView(mTableLayoutTrn);
    ll.addView(textViewPsnDtls);
    ll.addView(mTableLayoutPsn);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(ll);
    if (isWaitingList && !mPNRList.contains(mPNRNumber)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Track this PNR?");
        builder.setMessage("Would you like this PNR to be tracked for status change?");
        builder.setPositiveButton("Track", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //save the pnr
                pnrDB.addPNRToTrack(mPNRNumber);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("No thanks", null);
        builder.create().show();
    }

}

From source file:com.example.SmartBoard.DrawingView.java

public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) {
    TextView textView = new TextView(getContext());
    textView.setVisibility(View.VISIBLE);
    textView.setTextColor(color);// ww w  .j  a  v a  2s.c  o m
    textView.setMaxWidth(500);
    textView.setMaxHeight(500);
    textView.setMaxLines(4);
    textView.setX(posX);
    textView.setY(posY);
    textView.setText(text);
    textView.setTextSize(size);

    LinearLayout layout = new LinearLayout(getContext());
    layout.addView(textView);
    layout.measure(500, 500);
    layout.layout(0, 0, 500, 500);

    textView.setDrawingCacheEnabled(true);
    textView.buildDrawingCache();
    Bitmap bm = textView.getDrawingCache();
    return bm;
}

From source file:com.honeycomb.cocos2dx.Soccer.java

private void attachAd(final LinearLayout layout) {
    this.runOnUiThread(new Runnable() {
        @Override//from   w  w  w.  j  a v a  2s.  c om
        public void run() {
            if (isGooglePlay) {
                if (adView == null) {
                    if (isLargeDevice) {
                        adView = new AdView(Soccer.this);
                        adView.setAdSize(AdSize.LEADERBOARD);
                    } else {
                        adView = new AdView(Soccer.this);
                        adView.setAdSize(AdSize.BANNER);
                    }
                    adView.setAdUnitId("ca-app-pub-2442035138707094/7318464369");
                    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                            .addTestDevice("F38303E87BE23CE2B501B4CECED6DF0F")
                            .addTestDevice("86B9EA564072174EEC460A3D2A343265").build();

                    // Start loading the ad in the background.
                    adView.loadAd(adRequest);
                    // samsung galaxy tab
                    // adRequest.addTestDevice("8B4248C5362C18F658803042A2F868C4");
                    adView.loadAd(adRequest);
                    layout.addView(adView);
                } else {
                    layout.addView(adView);
                }
            } else {

            }
        }
    });
}

From source file:com.googlecode.networklog.LogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MyLog.d("[LogFragment] onCreateView");
    LinearLayout layout = new LinearLayout(getActivity().getApplicationContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    ListView listView = new ListView(getActivity().getApplicationContext());
    listView.setAdapter(adapter);/*from ww w .  j a  va  2 s.  c  o m*/
    listView.setTextFilterEnabled(true);
    listView.setFastScrollEnabled(true);
    listView.setSmoothScrollbarEnabled(false);
    listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    listView.setStackFromBottom(true);
    listView.setOnItemClickListener(new CustomOnItemClickListener());
    layout.addView(listView);
    registerForContextMenu(listView);
    startUpdater();
    return layout;
}