List of usage examples for android.widget LinearLayout addView
public void addView(View child)
Adds a child view.
From source file:com.actionbarsherlock.sample.demos.app.ActionBarActionItemCustomView.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem item = menu.add(0, android.R.id.copy, 0, "Test"); final int twentyDp = (int) (20 * getResources().getDisplayMetrics().density); TypedArray a = getTheme().obtainStyledAttributes(R.styleable.SherlockTheme); final int abHeight = a.getLayoutDimension(R.styleable.SherlockTheme_abHeight, LayoutParams.FILL_PARENT); a.recycle();//from www. j av a 2 s. co m LinearLayout l = new LinearLayout(this); l.setPadding(twentyDp, 0, twentyDp, 20); l.setBackgroundColor(0x55FF0000); TextView tv = new TextView(this); tv.setText("HI!!"); tv.setGravity(Gravity.CENTER); tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, abHeight)); l.addView(tv); l.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(ActionBarActionItemCustomView.this, "Got custom action item click!", Toast.LENGTH_SHORT).show(); } }); item.setActionView(l); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); return super.onCreateOptionsMenu(menu); }
From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivity.java
/** * Launch record search query// w ww . j a v a 2s . com * @param searchQuery Search string * @param ticket Intent tracker id */ protected void launchSearch(final String searchQuery, final int ticket) { final List<ListItem> resultList = new ArrayList<ListItem>(); final ClassyFyApplication classyFyApplication = ClassyFyApplication.getInstance(); AsyncBackgroundTask queryTask = new AsyncBackgroundTask(classyFyApplication) { /** * Execute task in background thread * Called on a worker thread to perform the actual load. * @return Boolean object - Boolean.TRUE indicates successful result * @see android.support.v4.content.AsyncTaskLoader#loadInBackground() */ @Override public Boolean loadInBackground() { resultList.addAll(classyfyLogic.doSearchQuery(searchQuery)); return Boolean.TRUE; } @Override public void onLoadComplete(Loader<Boolean> loader, Boolean success) { if (success) { success = resultList.size() > 0; if (success) { LinearLayout propertiesLayout = (LinearLayout) findViewById(R.id.node_properties); propertiesLayout.addView(createDynamicLayout("Titles", resultList, false)); } if (resultList.size() >= ClassyFyProvider.SEARCH_RESULTS_LIMIT) displayToast(REFINE_SEARCH_MESSAGE); } if (!success) { showTitle(RECORD_NOT_FOUND); displayToast("Search for \"" + searchQuery + "\" returned no records"); } ticketManager.removeIntent(ticket); } }; showTitle("Search: " + searchQuery); queryTask.onStartLoading(); }
From source file:com.hctrom.romcontrol.fastergps.ui.HelpHtmlFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mActivity = getActivity();/*from w w w.j av a 2 s. co m*/ LinearLayout layout = new LinearLayout(mActivity); HtmlTextView text = new HtmlTextView(mActivity); // padding int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, mActivity.getResources().getDisplayMetrics()); text.setPadding(padding, padding, padding, 0); layout.addView(text); // load html into textview text.setHtmlFromRawResource(mActivity, R.raw.help); // no flickering when clicking textview for Android < 4 text.setTextColor(getResources().getColor(android.R.color.secondary_text_dark_nodisable)); return layout; }
From source file:samsungsami.io.example.samiremotecontrol.DeviceActivity.java
public void addFallback() { final ObjectMapper mapper = new ObjectMapper(); TextView textView = new TextView(this); textView.setText("fallback"); LinearLayout gridLayout = (LinearLayout) findViewById(R.id.gridLayout); gridLayout.addView(textView); final EditText editText; editText = new EditText(this); Button button = new Button(this); button.setText("send"); button.setTextAppearance(this, android.R.style.TextAppearance_Small); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MessagesApi msgApi = new MessagesApi(); msgApi.setBasePath(SamiHelper.SAMIHUB_BASE_PATH); msgApi.getInvoker().addDefaultHeader("Authorization", "bearer " + SamiHelper.getAccessToken()); sendCommandMessage = new Message(); sendCommandMessage.setSdid(did); sendCommandMessage.setDdid(did); sendCommandMessage.setToken("fakeToken"); try { Map<String, Object> messageData = mapper.readValue(editText.getText().toString(), Map.class); sendCommandMessage.setData(messageData); new CallPostMessageApiInBackground().execute(msgApi); } catch (IOException e) { }//from w w w . ja v a 2 s .c o m } }); gridLayout.addView(editText); gridLayout.addView(button); }
From source file:com.google.android.car.kitchensink.input.InputTestFragment.java
private void addButtonsToPanel(LinearLayout root, List<View> buttons) { LinearLayout panel = null;//from www . j a v a 2s.c o m for (View button : buttons) { if (button == BREAK_LINE || panel == null) { panel = new LinearLayout(getContext()); panel.setOrientation(LinearLayout.HORIZONTAL); root.addView(panel); } else { panel.addView(button); } } }
From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivity.java
/** * Display record details//from w ww . ja va 2 s . c o m * @param nodeDetails NodeDetailsBean object */ protected void showRecordDetails(NodeDetailsBean nodeDetails) { showTitle(nodeDetails.getHeading()); LinearLayout propertiesLayout = (LinearLayout) findViewById(R.id.node_properties); if (nodeDetails.getHierarchy().size() > 0) propertiesLayout.addView(createDynamicLayout("Hierarchy", nodeDetails.getHierarchy(), true)); if (nodeDetails.getCategoryTitles().size() > 0) propertiesLayout.addView(createDynamicLayout("Categories", nodeDetails.getCategoryTitles(), true)); if (nodeDetails.getFolderTitles().size() > 0) propertiesLayout.addView(createDynamicLayout("Folders", nodeDetails.getFolderTitles(), true)); propertiesLayout.addView(createDynamicLayout("Details", nodeDetails.getFieldList(), false)); }
From source file:org.quantumbadger.redreader.activities.AlbumListingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PrefsUtility.applyTheme(this); OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, getString(R.string.imgur_album)); if (getActionBar() != null) { getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true); }/*from w ww . j a v a 2 s . c o m*/ final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences) && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT; if (solidblack) getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); final Intent intent = getIntent(); mUrl = intent.getDataString(); if (mUrl == null) { finish(); return; } final Matcher matchImgur = LinkHandler.imgurAlbumPattern.matcher(mUrl); final String albumId; if (matchImgur.find()) { albumId = matchImgur.group(2); } else { Log.e("AlbumListingActivity", "URL match failed"); revertToWeb(); return; } Log.i("AlbumListingActivity", "Loading URL " + mUrl + ", album id " + albumId); final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); progressBar.setIndeterminate(true); final LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(progressBar); ImgurAPI.getAlbumInfo(this, albumId, Constants.Priority.IMAGE_VIEW, 0, new GetAlbumInfoListener() { @Override public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { Log.e("AlbumListingActivity", "getAlbumInfo call failed: " + type); if (status != null) Log.e("AlbumListingActivity", "status was: " + status.toString()); if (t != null) Log.e("AlbumListingActivity", "exception was: ", t); // It might be a single image, not an album if (status == null) { revertToWeb(); return; } ImgurAPI.getImageInfo(AlbumListingActivity.this, albumId, Constants.Priority.IMAGE_VIEW, 0, new GetImageInfoListener() { @Override public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { Log.e("AlbumListingActivity", "Image info request also failed: " + type); revertToWeb(); } @Override public void onSuccess(final ImageInfo info) { Log.i("AlbumListingActivity", "Link was actually an image."); LinkHandler.onLinkClicked(AlbumListingActivity.this, info.urlOriginal); finish(); } @Override public void onNotAnImage() { Log.i("AlbumListingActivity", "Not an image either"); revertToWeb(); } }); } @Override public void onSuccess(final ImgurAPI.AlbumInfo info) { Log.i("AlbumListingActivity", "Got album, " + info.images.size() + " image(s)"); AndroidApi.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { if (info.title != null && !info.title.trim().isEmpty()) { OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, getString(R.string.imgur_album) + ": " + info.title); } layout.removeAllViews(); final ListView listView = new ListView(AlbumListingActivity.this); listView.setAdapter(new AlbumAdapter(info)); layout.addView(listView); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { LinkHandler.onLinkClicked(AlbumListingActivity.this, info.images.get(position).urlOriginal, false, null, info, position); } }); } }); } }); setContentView(layout); }
From source file:mx.com.adolfogarcia.popularmovies.model.view.MovieDetailViewModel.java
/** * Removes all views from the {@link LinearLayout} and adds new ones for * the specified {@link Review}s./*from w w w . j av a2 s.c o m*/ * * @param container {@link LinearLayout} that will contain the reviews. * @param reviews the {@link Review}s to be placed in the container. */ @BindingAdapter({ "bind:reviews" }) public static void loadReviewViews(LinearLayout container, List<Review> reviews) { container.removeAllViews(); if (reviews == null || reviews.isEmpty()) { return; } LayoutInflater inflater = (LayoutInflater) container.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (Review review : reviews) { MovieReviewListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_movie_review, container, false); MovieReviewListItemViewModel itemViewModel = new MovieReviewListItemViewModel(); itemViewModel.setReview(review); binding.setViewModel(itemViewModel); container.addView(binding.getRoot()); } }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private void populateFourthForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_zip_title))); EditText zipEditText = createEditText(mContext.getString(R.string.account_create_zip_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_GO, true, ZIP_KEY); if (mFormData.get(ZIP_KEY) != null) { zipEditText.setText(mFormData.get(ZIP_KEY)); }/*from w ww . java2 s . c o m*/ formLayout.addView(zipEditText); formLayout.addView(createErrorView(ZIP_KEY)); }
From source file:com.grarak.kerneladiutor.utils.ViewUtils.java
public static Dialog dialogEditTexts(String text, String text2, String hint, String hint2, final DialogInterface.OnClickListener negativeListener, final onDialogEditTextsListener onDialogEditTextListener, Context context) { LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding); layout.setPadding(padding, padding, padding, padding); final AppCompatEditText editText = new AppCompatEditText(context); editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (text != null) { editText.append(text);/*from ww w . java 2 s . c o m*/ } if (hint != null) { editText.setHint(hint); } editText.setSingleLine(true); final AppCompatEditText editText2 = new AppCompatEditText(context); editText2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (text2 != null) { editText2.setText(text2); } if (hint2 != null) { editText2.setHint(hint2); } editText2.setSingleLine(true); layout.addView(editText); layout.addView(editText2); Dialog dialog = new Dialog(context).setView(layout); if (negativeListener != null) { dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener); } if (onDialogEditTextListener != null) { dialog.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { onDialogEditTextListener.onClick(editText.getText().toString(), editText2.getText().toString()); } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (negativeListener != null) { negativeListener.onClick(dialog, 0); } } }); } return dialog; }