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 void updateView(int index){ View v = yourListView.getChildAt(index - yourListView.getFirstVisiblePosition()); if(v == null) return; TextView someText = (TextView) v.findViewById(R.id.sometextview); someText.setText("Hi! I updated you manually!"); }
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();
mScanReceiver = new ScanReceiver(); mConnectionReceiver = new ConnectionReceiver(); mStatusText = (TextView) v.findViewById(R.id.scanStatusText); mAdapter = new ScanAdapter(); mKeyList = new ArrayList<>(); mStatusText.setText( getString(R.string.wifi_initializing) ); mStatusText.setText( getString(R.string.wifi_activating_iface) ); mWifiManager.setWifiEnabled(true); mStatusText.setText(getString(R.string.wifi_activated)); mStatusText.setText( getString(R.string.wifi_scanning) ); mScanning = true;
intent.putParcelableArrayListExtra("files", new ArrayList<File>(Arrays.asList(files))); startService(intent); bar.setProgress(file.progress); TextView tv = (TextView) v.findViewById(R.id.textView); tv.setText(file.toString()); v.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mEcs = new ExecutorCompletionService<NoResultType>(mExec); mBroadcastManager = LocalBroadcastManager.getInstance(this); mTasks = new ArrayList<MainActivity.DownloadingService.DownloadTask>();
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));
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class FirstActivity extends RootActivity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.tvTitle); tv.setText("First Activity"); Button bt = (Button) findViewById(R.id.buttonNext); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(FirstActivity.this, SecondActivity.class); startActivity(i); } }); } }
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; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewGroup view; if (convertView == null) { view = (ViewGroup) mInflater.inflate(R.layout.rounded_item, parent, false); } else { view = (ViewGroup) convertView; } ColorItem item = getItem(position); ((ImageView) view.findViewById(R.id.imageView1)).setImageResource(item.mResId); ((ImageView) view.findViewById(R.id.imageView1)).setScaleType(item.mScaleType); ((TextView) view.findViewById(R.id.textView1)).setText(item.mLine1); ((TextView) view.findViewById(R.id.textView2)).setText(item.mLine2); ((TextView) view.findViewById(R.id.textView3)).setText(item.mScaleType.toString()); return view; } }
LayoutParams lparams = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); TextView tv=new TextView(this); tv.setLayoutParams(lparams); tv.setText("test"); this.m_vwJokeLayout.addView(tv);
TableLayout table = new TableLayout(this); TableRow tr = new TableRow(this); tr.setBackgroundColor(Color.BLACK); tr.setPadding(0, 0, 0, 2); //Border between rows TableRow.LayoutParams llp = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); llp.setMargins(0, 0, 2, 0);//2px right-margin //New Cell LinearLayout cell = new LinearLayout(this); cell.setBackgroundColor(Color.WHITE); cell.setLayoutParams(llp);//2px border on the right for the cell TextView tv = new TextView(this); tv.setText("Some Text"); tv.setPadding(0, 0, 4, 3); cell.addView(tv); tr.addView(cell); //add as many cells you want to a row, using the same approach table.addView(tr);
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) {
findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { findViewById(R.id.btn_forward).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(text != null) mTextView.setText(text);
public View getView(int position, View convertView, ViewGroup parent){ // TODO Auto-generated method stub View v; if(convertView==null) { LayoutInflater li = getLayoutInflater(); v = li.inflate(R.layout.icontext, null); }else{ v = convertView; } TextView tv = (TextView)v.findViewById(R.id.icon_text); tv.setText(providers[position]); ImageView iv = (ImageView)v.findViewById(R.id.icon_image); iv.setImageResource(R.drawable.icon); return v; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fr_simple_card, null); TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv); card_title_tv.setText(mTitle); return v; } }
@Override public Object instantiateItem(ViewGroup container, int position) { TextView textView = new TextView(container.getContext()); textView.setText(mDataList.get(position)); textView.setGravity(Gravity.CENTER); textView.setTextColor(Color.BLACK); textView.setTextSize(24); container.addView(textView); return textView; }
import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class SecondActivity extends RootActivity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.tvTitle); tv.setText("Second Activity"); Button bt = (Button) findViewById(R.id.buttonNext); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(SecondActivity.this, ThirdActivity.class); startActivity(i); } }); } }
public void showNetworkError(View.OnClickListener onClickListener) { View layout = helper.inflate(R.layout.message); TextView textView = (TextView) layout.findViewById(R.id.message_info); textView.setText(helper.getContext().getResources().getString(R.string.common_no_network_msg)); ImageView imageView = (ImageView) layout.findViewById(R.id.message_icon); imageView.setImageResource(R.drawable.ic_exception); if (null != onClickListener) { layout.setOnClickListener(onClickListener); } helper.showLayout(layout); }