AlertDialog.Builder builder; AlertDialog alertDialog; Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) findViewById(R.id.layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("Hello, this is a custom dialog!"); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(R.drawable.android); builder = new AlertDialog.Builder(mContext); builder.setView(layout); alertDialog = builder.create();
protected TextView createMaskView(Context context, String text, int textSize, int gravity) { final TextView maskView = new TextView(context); maskView.setTextColor(Color.BLACK); maskView.setGravity(gravity | Gravity.CENTER_HORIZONTAL); maskView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); maskView.setText(text); //noinspection UnnecessaryLocalVariable final View view = maskView; view.setBackgroundColor(Color.WHITE); return maskView; }
private HttpImageGetter hide(final TextView view) { view.setText(null); view.setVisibility(GONE); view.setTag(null); return this; }
protected View initializeContentView(boolean isSmartLogin) { View view; LayoutInflater inflater = getActivity().getLayoutInflater(); view = inflater.inflate(getLayoutResId(isSmartLogin), null); progressBar = view.findViewById(R.id.progress_bar); confirmationCode = (TextView)view.findViewById(R.id.confirmation_code); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onCancel(); } }); instructions = (TextView) view.findViewById( R.id.com_facebook_device_auth_instructions); instructions.setText( Html.fromHtml(getString(R.string.com_facebook_device_auth_instructions))); return view; }
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = vi.inflate(R.layout.your_layout, null); // fill in any details dynamically here TextView textView = (TextView) v.findViewById(R.id.a_text_view); textView.setText("your text"); // insert into main view ViewGroup insertPoint = (ViewGroup) findViewById(R.id.insert_point); insertPoint.addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
public View getView(int position, View convertView, ViewGroup parent) { View v; if (convertView == null) { // if it's not recycled, initialize some attributes LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); v = inflater.inflate(R.layout.gridview_item_layout, parent, false); } else { v = (View) convertView; } TextView text = (TextView)v.findViewById(R.id.grid_item_text); text.setText(mTextIds[position]); ImageView image = (ImageView)v.findViewById(R.id.grid_item_image); image.setImageDrawable(mThumbIds[position]); return v; }
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(layoutResId, container, false); ((TextView)view.findViewById(R.id.custom_slide_big_text)).setText(mTitle); if (mButtonText != null) { Button button = view.findViewById(R.id.custom_slide_button); button.setVisibility(View.VISIBLE); button.setText(mButtonText); button.setOnClickListener(mButtonListener); } return view; } }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = mLayoutInflater.inflate(R.layout.choose_account_row, null); holder = new ViewHolder(); holder.text = (TextView) convertView.findViewById(R.id.account_row_text); holder.icon = (ImageView) convertView.findViewById(R.id.account_row_icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.text.setText(mInfos.get(position).name); holder.icon.setImageDrawable(mInfos.get(position).drawable); return convertView; } }
View view = inflater.inflate(R.layout.fragment_a, null); persistentVariableEdit = (EditText) view.findViewById(R.id.editText); TextView proofTextView = (TextView) view.findViewById(R.id.textView); proofTextView.setText(persistentVariable); view.findViewById(R.id.btnPushFragmentB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { public void onPause() { super.onPause(); String persistentVariable = persistentVariableEdit.getText().toString();
Button btn = (Button) convertView.findViewById(R.id.button); btn.setOnClickListener(this); TextView tv = (TextView) convertView.findViewById(R.id.text); tv.setText(text); convertView.setOnClickListener(new OnItemClickListener(position)); return convertView;
if (v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.row, null); RadioButton r = (RadioButton)v.findViewById(R.id.radiobutton); TextView tv = (TextView)v.findViewById(R.id.textview); tv.setText("Text view #" + position); RadioButton r = (RadioButton)v.findViewById(R.id.radiobutton); r.setChecked(position == selectedPosition); r.setTag(position); r.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {
button = (Button) findViewById(R.id.button); etMsg = (EditText)findViewById(R.id.etMsg); button.setOnClickListener(new OnClickListener() { text.setText(mIRemoteService.getMessage(etMsg.getText().toString())); } catch (RemoteException e) { e.printStackTrace();
public TransitionEditView(final Context context, @Nullable AttributeSet attrs) { super(context, attrs); mContext = context; View view = LayoutInflater.from(context).inflate(R.layout.transition_edit_view, this); mBackBtn = (Button) view.findViewById(R.id.back_button); mTitleEditText = (EditText) view.findViewById(R.id.title_edit_text); mSubtitleEditText = (EditText) view.findViewById(R.id.subtitle_edit_text); mNumberPicker = (NumberPicker) view.findViewById(R.id.number_picker); mColorGroup = (ViewGroup) view.findViewById(R.id.color_group); mConfirmText = (TextView) view.findViewById(R.id.text_confirm); mConfirmText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mSizeGroup.setOnClickListener(mOnClickListener); mTypefaceGroup.setOnClickListener(mOnClickListener); mTitleEditText.setOnFocusChangeListener(mOnFocusChangeListener); mSubtitleEditText.setOnFocusChangeListener(mOnFocusChangeListener); mBackBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
private void bindView(int position, View row) { TextView label=(TextView)row.findViewById(R.id.label); label.setText(getItem(position).loadLabel(pm)); ImageView icon=(ImageView)row.findViewById(R.id.icon); icon.setImageDrawable(getItem(position).loadIcon(pm)); } }
private View addItemView(final String title, @DrawableRes final int icon, ViewGroup container) { final View itemRoot = View.inflate(getContext(), R.layout.subscription_import_export_item, null); final TextView titleView = itemRoot.findViewById(android.R.id.text1); final ImageView iconView = itemRoot.findViewById(android.R.id.icon1); titleView.setText(title); iconView.setImageResource(icon); container.addView(itemRoot); return itemRoot; }
@Test @Config(qualifiers = "sw720dp") public void inflateLayout_overridesTo_sw720dp() throws Exception { View view = Robolectric.setupActivity(Activity.class).getLayoutInflater().inflate(R.layout.layout_smallest_width, null); TextView textView = view.findViewById(R.id.text1); assertThat(textView.getText()).isEqualTo("720"); assertThat(resources.getConfiguration().smallestScreenWidthDp).isEqualTo(720); }
TextView txt = (TextView) findViewById(R.id.output); txt.setText("Executed");
public class ViewDialog { public void showDialog(Activity activity, String msg){ final Dialog dialog = new Dialog(activity); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false); dialog.setContentView(R.layout.dialog); TextView text = (TextView) dialog.findViewById(R.id.text_dialog); text.setText(msg); Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog); dialogButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }
TextView txtName = (TextView) convertView.findViewById(R.id.nameEdit); txtName.setText(score.getName()); Button b = (Button)convertView.findViewById(R.id.deletePlayer); b.setTag(position); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {