ListView lv = (ListView) findViewById(R.id.layout_lv); lv.setOnTouchListener(new OnTouchListener() { // Setting on Touch Listener for handling the touch inside ScrollView @Override public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of child view v.getParent().requestDisallowInterceptTouchEvent(true); return false; } });
View namebar = view.findViewById(R.id.namebar); ((ViewGroup) namebar.getParent()).removeView(namebar);
pager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.getParent().requestDisallowInterceptTouchEvent(true); return false; } }); pager.setOnPageChangeListener(new SimpleOnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mPager.getParent().requestDisallowInterceptTouchEvent(true); } });
actionBar.setLogo(null); // forgot why this one but it helped View homeIcon = findViewById( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.id.home : R.id.abs__home); ((View) homeIcon.getParent()).setVisibility(View.GONE); ((View) homeIcon).setVisibility(View.GONE); actionBar.setDisplayShowTitleEnabled(false);
public void deleteButtonClick(View v) { //TODO Remove favorite - DB + file system Toast.makeText(this, "Deleting bookmark", Toast.LENGTH_SHORT).show(); final int position = getListView().getPositionForView((LinearLayout)v.getParent()); if (position >= 0) { Favorite o = (Favorite) this.getListAdapter().getItem(position); } }
private static View view; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view != null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) parent.removeView(view); } try { view = inflater.inflate(R.layout.map, container, false); } catch (InflateException e) { /* map is already there, just return view as it is */ } return view; }
View homeIcon = findViewById(android.R.id.home); ((View) homeIcon.getParent()).setVisibility(View.GONE);
int optionId = someExpression ? R.layout.option1 : R.layout.option2; View C = findViewById(R.id.C); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C); C = getLayoutInflater().inflate(optionId, parent, false); parent.addView(C, index);
ListView lv = (ListView)findViewById(R.id.myListView); // your listview inside scrollview lv.setOnTouchListener(new ListView.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: // Disallow ScrollView to intercept touch events. v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: // Allow ScrollView to intercept touch events. v.getParent().requestDisallowInterceptTouchEvent(false); break; } // Handle ListView touch events. v.onTouchEvent(event); return true; } });
public static void sendViewToBack(final View child) { final ViewGroup parent = (ViewGroup)child.getParent(); if (null != parent) { parent.removeView(child); parent.addView(child, 0); } }
getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.WHITE)); LayoutInflater mInflater = LayoutInflater.from(this); View mCustomView = mInflater.inflate(R.layout.action_bar_home, null); getSupportActionBar().setCustomView(mCustomView); getSupportActionBar().setDisplayShowCustomEnabled(true); Toolbar parent =(Toolbar) mCustomView.getParent();//first get parent toolbar of current action bar parent.setContentInsetsAbsolute(0,0);// set padding programmatically to 0dp
View yourView = ...; ViewGroup viewParent = (ViewGroup) yourView.getParent(); viewParent.removeView(yourView);
EditText EtOne = (EditText) findViewById(R.id.EditText01); EtOne.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (v.getId() == R.id.EditText01) { v.getParent().requestDisallowInterceptTouchEvent(true); switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } });
EditText dwEdit = (EditText) findViewById(R.id.DwEdit); dwEdit.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub if (view.getId() ==R.id.DwEdit) { view.getParent().requestDisallowInterceptTouchEvent(true); switch (event.getAction()&MotionEvent.ACTION_MASK){ case MotionEvent.ACTION_UP: view.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } });
// We get the View of the Activity View content = (View) activity.findViewById(android.R.id.content).getParent(); // And its parent ViewGroup parent = (ViewGroup) content.getParent(); // The container for the menu Fragment is a FrameLayout // We set an id so we can perform FragmentTransactions later on FrameLayout menuContainer = new FrameLayout(this.activity); menuContainer.setId(R.id.flMenuContainer); // The visibility is set to GONE because the menu is initially hidden menuContainer.setVisibility(View.GONE); // The container for the menu Fragment is added to the parent parent.addView(menuContainer);
public void onToggle(View view) { ((RadioGroup)view.getParent()).check(view.getId()); // app specific stuff .. }
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; } }
ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowTitleEnabled(false); View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null); actionBar.setCustomView(customView); Toolbar parent =(Toolbar) customView.getParent(); parent.setPadding(0,0,0,0);//for tab otherwise give space in tab parent.setContentInsetsAbsolute(0,0);