class ButtonListener implements android.view.View.OnClickListener { public void onClick(View v) { View parent = (View)v.getParent(); if (parent != null) { TextView txtView = parent.findViewById(R.id.mytextview); txtView.setText(...); } } }
public class FragmentA extends Fragment { View _rootView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (_rootView == null) { // Inflate the layout for this fragment _rootView = inflater.inflate(R.layout.fragment_a, container, false); // Find and setup subviews _listView = (ListView)_rootView.findViewById(R.id.listView); ... } else { // Do not inflate the layout again. // The returned View of onCreateView will be added into the fragment. // However it is not allowed to be added twice even if the parent is same. // So we must remove _rootView from the existing parent view group // (it will be added back). ((ViewGroup)_rootView.getParent()).removeView(_rootView); } return _rootView; } }
public class FragmentA extends Fragment { View _rootView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (_rootView == null) { // Inflate the layout for this fragment _rootView = inflater.inflate(R.layout.fragment_a, container, false); // Find and setup subviews _listView = (ListView)_rootView.findViewById(R.id.listView); ... } else { // Do not inflate the layout again. // The returned View of onCreateView will be added into the fragment. // However it is not allowed to be added twice even if the parent is same. // So we must remove _rootView from the existing parent view group // in onDestroyView() (it will be added back). } return _rootView; } @Override public void onDestroyView() { if (_rootView.getParent() != null) { ((ViewGroup)_rootView.getParent()).removeView(_rootView); } super.onDestroyView(); } }
EditText comment = (EditText) view.findViewById(R.id.wo_task_comments);
public class DadosPonto extends Fragment{ // Keep a reference to the view; private View view; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view == null) { view = inflater.inflate(R.layout.dados_ponto_layout, container, false); View idPonto = view.findViewById(R.id.idPonto); // ..... } else { // If we are returning from a configuration change: // "view" is still attached to the previous view hierarchy // so we need to remove it and re-attach it to the current one ViewGroup parent = (ViewGroup) view.getParent(); parent.removeView(view); } return view; } }
TextView tv = (TextView) header.findViewById( R.id.program_title ); tv.setText( textToSet );
@Override protected void onListItemClick(ListView l, View v, int position, long id) { View view = (View)v.getParent(); TextView txtTechCharacteristic = (TextView) view.findViewById(R.id.techCharacteristic); TextView txtTechCharacteristicName = (TextView) view.findViewById(R.id.techCharacteristicName); }
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View addView = layoutInflater.inflate(R.layout.row, null); TextView textOut = (TextView)addView.findViewById(R.id.textout); textOut.setText(textIn.getText().toString()); Button buttonRemove = (Button)addView.findViewById(R.id.remove); buttonRemove.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { ((LinearLayout)addView.getParent()).removeView(addView); }}); container.addView(addView);
public void onRadioButtonClicked(View v) { RadioButton rb = (RadioButton) v; // Toast.makeText(getApplicationContext(), // rb.getText(),Toast.LENGTH_SHORT).show(); View Rg = (View) rb.getParent(); View LLayout = (View) Rg.getParent(); TextView txtLvId = (TextView) LLayout.findViewById(R.id.txtLvid); String LvID = txtLvId.getText().toString(); }
@Override public void bindView(View view, Context context, Cursor cursor) { ImageView overflowMenu = (ImageView) view.findViewById(R.id.yourId); overflowMenu.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { //Get position of the item clicked final int position = getListView().getPositionForView((LinearLayout)v.getParent()); //Get the cursor of the item clicked final Cursor c = (Cursor) getListView().getItemAtPosition(position); } }
boldButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { View parentView = (View) view.getParent(); CheckBox checkBox = (CheckBox) parentView.findViewById(R.id.check); } });
public void onClick(View v) { // since each pager includes an ImageView and a TextView // get the current pager which is the parent of the current ImageView View currentPage = (View) v.getParent(); // find the TextView within the current page mCaption = (TextView) currentPage.findViewById(R.id.caption); ...
//a variable, you could use from all the methods, that will have as a value the value of the selected TextView private String selectedValue; @Override protected void onListItemClick(ListView l, View v, int position, long id) { View view = (View)v.getParent(); TextView textYouNeed = (TextView) view.findViewById(R.id.textViewId); selectedValue = textYouNeed.getText(); }
@Override public void onClick(View v) { Intent intent = new Intent(getContext(), ClassActivity.class); //It's the parent of the parent OF THE parent where //the textView lies in my layout. View parent = (View) v.getParent().getParent().getParent(); TextView title = (TextView) parent.findViewById(R.id.fragment_student_home_classTitle_textView); System.out.println("\n\n title: " + title.getText().toString() + " \n\n"); intent.putExtra("__CLASS_NAME__", title.getText().toString());
holder.ans.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View vi = (View) v.getParent(); TextView texview = (TextView) vi.findViewById(R.id.txt_ans); textview.setText("Answer is correct"); textview.setVisiblity(View.VISIBLE); } });
private OnClickListener mClickListener = new OnClickListener() { @Override public void onClick(View v) { View view = (View) v.getParent(); TextView tv = (TextView) view.findViewById(R.id.txtV_player_input_position_title); String s = tv.getText().toString(); Intent intent = new Intent(); intent.setClass(context, PlayerActivity.class); intent.putExtra("name", s); context.startActivity(intent); } };
protected void removeAdView(int adViewId) { View view = getWindow().getDecorView(); View adView = view.findViewById(adViewId); if (adView != null) { ViewGroup parent = (ViewGroup) adView.getParent(); parent.removeView(adView); parent.invalidate(); } }
protected void removeAdView(View topView, int adViewId) { View adView = topView.findViewById(adViewId); if (adView != null) { ViewGroup parent = (ViewGroup) adView.getParent(); parent.removeView(adView); parent.invalidate(); } }
View child = parent.findViewById(R.id.btnMoreText); child.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { View parent = (View) v.getParent(); parent.performClick(); } });
public void onRadioButtonClick(View v) { RadioButton rb = (RadioButton) v; Toast.makeText(getApplicationContext(), rb.getText(),Toast.LENGTH_SHORT).show(); View Rg = (View) rb.getParent(); View LLayout = (View) Rg.getParent(); TextView txtLvId = (TextView) LLayout.findViewById(R.id.ins_itemid); String LvID = txtLvId.getText().toString(); Toast.makeText(getApplicationContext(), LvID, Toast.LENGTH_LONG).show(); }