List of usage examples for android.widget LinearLayout addView
public void addView(View child)
Adds a child view.
From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java
protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, final Uri uri, final LocalGeoJsonLayer layer) { final LinearLayout linearLayout = new LinearLayout(map.getContext()); final EditText input = new EditText(map.getContext()); input.setText(layerName);// ww w . j a v a2s. c om final TextView stLayerName = new TextView(map.getContext()); stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":"); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(stLayerName); linearLayout.addView(input); if (!bCreate) { //TODO: style for drawing } new AlertDialog.Builder(map.getContext()) .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties) // .setMessage(message) .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (bCreate) { create(map, input.getText().toString(), uri); } else { layer.setName(input.getText().toString()); map.onLayerChanged(layer); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show(); } }).show(); }
From source file:Main.java
public static View getTestFragmentView(Activity activity, OnClickListener clickListener) { LinearLayout v = new LinearLayout(activity); v.setBackgroundColor(Color.BLUE); v.setOrientation(LinearLayout.VERTICAL); TextView tv1 = new TextView(activity); TextView tv2 = new TextView(activity); Button b1 = new Button(activity); Button b2 = new Button(activity); Button b3 = new Button(activity); b1.setText("reload 1"); b2.setText("reload 2"); b3.setText("reload all"); b1.setId(1);/*w w w. j a v a 2 s . c om*/ b2.setId(2); b3.setId(3); tv1.setId(android.R.id.text1); tv2.setId(android.R.id.text2); b1.setOnClickListener(clickListener); b2.setOnClickListener(clickListener); b3.setOnClickListener(clickListener); v.addView(tv1); v.addView(tv2); v.addView(b1); v.addView(b2); v.addView(b3); return v; }
From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java
/** * Select a custom item from a list, and call halder when/if item is selected. */// w w w . ja v a 2 s .c o m public static void selectItemDialog(LayoutInflater inflater, String message, ArrayList<SimpleDialogItem> items, SimpleDialogItem selectedItem, final SimpleDialogOnClickListener handler) { // Get the view and the radio group final View root = inflater.inflate(R.layout.select_list_dialog, null); TextView msg = (TextView) root.findViewById(R.id.message); // Build the base dialog final AlertDialog.Builder builder = new AlertDialog.Builder(inflater.getContext()).setView(root); if (message != null && !message.equals("")) { msg.setText(message); } else { msg.setVisibility(View.GONE); } final AlertDialog dialog = builder.create(); // Create the listener for each item OnClickListener listener = new OnClickListener() { @Override public void onClick(View v) { SimpleDialogItem item = (SimpleDialogItem) ViewTagger.getTag(v, R.id.TAG_DIALOG_ITEM); // For a consistent UI, make sure the selector is checked as well. NOT mandatory from // a functional point of view, just consistent if (!(v instanceof RadioButton)) { RadioButton btn = item.getSelector(v); if (btn != null) { btn.setChecked(true); btn.invalidate(); } } // // It would be nice to have the other radio buttons reflect the new state before it // disappears, but not really worth the effort. Esp. since the code below does not work... // and the dialog disappears too fast to make this worthwhile. // //LinearLayout list = (LinearLayout)root.findViewById(R.id.list); //for(int i = 0; i < list.getChildCount(); i++) { // View child = list.getChildAt(i); // SimpleDialogItem other = (SimpleDialogItem)ViewTagger.getTag(child, R.id.TAG_DIALOG_ITEM); // RadioButton btn = other.getSelector(child); // btn.setSelected(other == item); // btn.invalidate(); //} dialog.dismiss(); handler.onClick(item); } }; // Add the items to the dialog LinearLayout list = (LinearLayout) root.findViewById(R.id.list); for (SimpleDialogItem item : items) { View v = item.getView(inflater); v.setBackgroundResource(android.R.drawable.list_selector_background); ViewTagger.setTag(v, R.id.TAG_DIALOG_ITEM, item); list.addView(v); v.setOnClickListener(listener); RadioButton btn = item.getSelector(v); if (btn != null) { ViewTagger.setTag(btn, R.id.TAG_DIALOG_ITEM, item); btn.setChecked(item == selectedItem); btn.setOnClickListener(listener); } } dialog.show(); }
From source file:com.grarak.kerneladiutor.utils.ViewUtils.java
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener, final OnDialogEditTextListener onDialogEditTextListener, int inputType, Context context) { LinearLayout layout = new LinearLayout(context); int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding); layout.setPadding(padding, padding, padding, padding); final AppCompatEditText editText = new AppCompatEditText(context); editText.setGravity(Gravity.CENTER); editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (text != null) { editText.append(text);//from ww w . ja v a 2 s.com } editText.setSingleLine(true); if (inputType >= 0) { editText.setInputType(inputType); } layout.addView(editText); 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()); } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (negativeListener != null) { negativeListener.onClick(dialog, 0); } } }); } return dialog; }
From source file:com.wellsandwhistles.android.redditsp.fragments.PostPropertiesDialog.java
@Override protected void prepare(AppCompatActivity context, LinearLayout items) { final RedditPost post = getArguments().getParcelable("post"); items.addView( propView(context, R.string.props_title, StringEscapeUtils.unescapeHtml4(post.title.trim()), true)); items.addView(propView(context, R.string.props_author, post.author, false)); items.addView(propView(context, R.string.props_url, StringEscapeUtils.unescapeHtml4(post.url), false)); items.addView(propView(context, R.string.props_created, SRTime.formatDateTime(post.created_utc * 1000, context), false)); if (post.edited instanceof Long) { items.addView(propView(context, R.string.props_edited, SRTime.formatDateTime((Long) post.edited * 1000, context), false)); } else {//from www. j av a2s. com items.addView(propView(context, R.string.props_edited, R.string.props_never, false)); } items.addView(propView(context, R.string.props_subreddit, post.subreddit, false)); items.addView(propView(context, R.string.props_score, String.valueOf(post.score), false)); items.addView(propView(context, R.string.props_num_comments, String.valueOf(post.num_comments), false)); if (post.selftext != null && post.selftext.length() > 0) { items.addView(propView(context, R.string.props_self_markdown, StringEscapeUtils.unescapeHtml4(post.selftext), false)); } }
From source file:com.wellsandwhistles.android.redditsp.fragments.CommentPropertiesDialog.java
@Override protected void prepare(AppCompatActivity context, LinearLayout items) { final RedditComment comment = getArguments().getParcelable("comment"); items.addView(propView(context, "ID", comment.name, true)); items.addView(propView(context, R.string.props_author, comment.author, false)); if (comment.author_flair_text != null && comment.author_flair_text.length() > 0) { items.addView(propView(context, R.string.props_author_flair, comment.author_flair_text, false)); }/*from w w w . ja va 2 s. c om*/ items.addView(propView(context, R.string.props_created, SRTime.formatDateTime(comment.created_utc * 1000, context), false)); if (comment.edited instanceof Long) { items.addView(propView(context, R.string.props_edited, SRTime.formatDateTime((Long) comment.edited * 1000, context), false)); } else { items.addView(propView(context, R.string.props_edited, R.string.props_never, false)); } items.addView(propView(context, R.string.props_score, String.valueOf(comment.ups - comment.downs), false)); items.addView(propView(context, R.string.props_subreddit, comment.subreddit, false)); if (comment.body != null && comment.body.length() > 0) { items.addView(propView(context, R.string.props_body_markdown, StringEscapeUtils.unescapeHtml4(comment.body), false)); } }
From source file:com.draekko.traypreferencesapp.SampleAppPreferences.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ViewGroup root = (ViewGroup) findViewById(android.R.id.content); LinearLayout content = (LinearLayout) root.getChildAt(0); LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar, null); root.removeAllViews();//from w w w . j a va 2 s. c om toolbarContainer.addView(content); root.addView(toolbarContainer); mToolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar); mToolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.white)); mToolbar.setSubtitleTextColor(ContextCompat.getColor(this, R.color.white)); mToolbar.setNavigationIcon(R.drawable.ic_back_material_light); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); }
From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java
/** * Removes all views from the {@link LinearLayout} and adds new ones for * the specified {@link Author}s./*from w ww . j av a 2s . c o m*/ * * @param container {@link LinearLayout} that will contain the authors. * @param authors the {@link Author}s to be placed in the container. */ @BindingAdapter({ "bind:authors" }) public static void loadAuthorViews(LinearLayout container, List<Author> authors) { container.removeAllViews(); if (authors == null || authors.isEmpty()) { return; } LayoutInflater inflater = (LayoutInflater) container.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (Author author : authors) { AuthorListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_author, container, false); AuthorListItemViewModel itemViewModel = new AuthorListItemViewModel(); itemViewModel.setAuthor(author); binding.setViewModel(itemViewModel); container.addView(binding.getRoot()); } }
From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java
/** * Removes all views from the {@link LinearLayout} and adds new ones for * the specified instances of {@link Category}. * * @param container {@link LinearLayout} that will contain the categories. * @param categories the instances of {@link Category} to be placed in the * container.// w ww .j a v a2 s . c o m */ @BindingAdapter({ "bind:categories" }) public static void loadCategoryViews(LinearLayout container, List<Category> categories) { container.removeAllViews(); if (categories == null || categories.isEmpty()) { return; } LayoutInflater inflater = (LayoutInflater) container.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (Category category : categories) { CategoryListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_category, container, false); CategoryListItemViewModel itemViewModel = new CategoryListItemViewModel(); itemViewModel.setCategory(category); binding.setViewModel(itemViewModel); container.addView(binding.getRoot()); } }
From source file:biz.easymenu.easymenung.FoodMenuFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout ll = new LinearLayout(getActivity()); ViewPager vp = new ViewPager(getActivity()); MenuPagerAdapter mpa = new MenuPagerAdapter(getActivity(), isDrinks); vp.setAdapter(mpa);//w ww . j av a 2 s .co m ll.addView(vp); return ll; }