im a android developer and need to do this:
Recycler view horizontal like facebook
enter image description here
Thats one recyclerview horizontal with a tablayout, i wanna do is while the user be scrolling de recycler view his cannot swipe the tab layout.
Like facebook tab videos
Create a recyclerView in the xml and add this code in the activity. You will achieve the horizontal scrolling without swiping the tab layout.
adapter = new Adapter(// pass your arguments);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recycleView.setLayoutManager(layoutManager);
recycleView.setAdapter(adapter);
recycleView.setNestedScrollingEnabled(false);
Related
I have this adapter which the text view instantiate.
But i want to change the text in the fragment.
what should i do?
Adapter which i used holder:
holder.btnRedeem = vi.findViewById(R.id.btnRedeem);
vi.setTag(holder);
Fragment:
(TextView)getView().findViewById(R.id.btnRedeem)).setText("redeem");
create an interface in your adapter and implement it in your fragment.
check my answer for this question:
https://stackoverflow.com/questions/58521136
check adapter and fragment (not activity)
if you want to handle in adapter
holder.btnRedeem.setText("redeem")
If you want to handle in Fragment, you need to get the position of your item & apply text to the TextView.
I want to create a "focus" effect once the user clicks an item in the recycler view. Look at the image below, the second one is the effect I wish to have.
I've tried to get the RecyclerView's clicked item and bring it to the front and show a dark/transparent overlay covering all the others.
This is my view hierarchy:
RelativeLayout
--- Recycler View
--- View (dark overlay)
I've tried with view.bringToFront();, view.setZ();, view.setElevation(); but none of them works.
Now I guess this is about the layout hierarchy. How to solve this problem?
you can just change the background color of touch item view and text color. when user click on it .
I achieved this effect by sending the item view to the Window.DecorView.
You can just make a copy of the desired view you want to put in the front (in this case you want the layout used by the ViewHolder) and then
((ViewGroup)activity.getWindow().getDecorView()).addView(yourView);
after that you can set Translations according to the original view. The new view will be in front of the dark overlay in the same place the previous view is
EDIT: I have a sample of what you can do:
The following code is C# (using Xamarin.Android), it should be easy to turn to Java.
var productView = productsLayoutManager.FindViewByPosition(position);
var cardView = productView.FindViewById<CardView>(Resource.Id.product_layout);
int[] location = new int[2];
productView.GetLocationOnScreen(location);
int left = location[0];
int top = location[1];
selectedView = LayoutInflater.Inflate(Resource.Layout.ProductRow2, null);
productsAdapter.CloneItemViewHolder(productView, ref selectedView);
selectedView.LayoutParameters = new FrameLayout.LayoutParams(cardView.LayoutParameters);
((ViewGroup)activity.Window.DecorView).AddView(selectedView, cardView.Width, cardView.Height);
selectedView.SetX(left);
selectedView.SetY(top);
selectedView.RequestLayout();
activity.DimBackground();
The cardView is the main layout of the RecyclerView item Viewholder.
This is actual code in use, producing this:
I have a class "HomeActivity.class" and its layout "activity_home". I need to change the text of a TextView ("TV8") in another layout ("layout_profile"). I tried to use:
setContentView(R.layout.activity_home);
ConstraintLayout profile=(ConstraintLayout)findViewById(R.id.layout_profile);
TextView TV8 = (TextView) findViewById(R.id.TV8);
TV8.setText("MY TEXT IN TV8");
but my app crush when try to set text at line 4.
Maybe the problem can be the inflated layout: in activty_home layout i have a frame layout that inflate layout_profile where is my textview TV8:
activity_home:
layout_profile :
Debug application
HOW CAN I CHANGE THE TEXT OF A TEXTVIEW (TV8) IN A LAYOUT(layout_profile) FROM A CLASS(activity_home) THAT HAVE ANOTHER LAYOUT(activty_home)??
I think there is an issue in line 3.
Try this:
setContentView(R.layout.activity_home);
ConstraintLayout profile=(ConstraintLayout)findViewById(R.id.layout_profile);
TextView TV8 = (TextView) profile.findViewById(R.id.TV8);
TV8.setText("MY TEXT IN TV8");
You are loading activity_home.xml in the Activity and try to access the view TV8 which is not in activty_home.xml.
R.id.TV8 is part of layout_profile not part of activity_home.xml.
You can access those view which is in layout which is currently loaded in the screen.
Your activity is loading the activity_main layout so you can access the views that are present in the layout.
You are trying to access the view present in layout_profile which is not loaded and not visible. Until its loaded you can't access the view.
And if the view is not visible there is no point changing the text of that view.
Rather you can store the value in a flag and can be used to change the text when layout_profile is loaded.
i want to create wallpaper app.
i want user click image show whole image and visible set wallpaper button.
like this pictures
after licked like this
The problem is to show set wallpaper button when image clicked and show whole image.
Thank you!
to display all image display activity use recyclerview with GridLayoutManagerlike this
private GridLayoutManager lLayout;
lLayout = new GridLayoutManager(MainActivity.this, 2);
recyclerview.setLayoutManager(lLayout);
check this link for how to use recyclerview with GridLayoutManager
for display image create a new activity and pass the image when user select image from recyclerview to that activity and display
Ask me in case of any query
I've been trying to get a widget from another layout for past hours but still no luck. Can someone tell what is wrong with my current code?
public void refreshClicked(View view){
tab1 = LayoutInflater.from(view.getContext()).inflate(R.layout.tab_1, null);
Button b = (Button) tab1.findViewById(R.id.refresh);
b.setText("Updating...");
}
I've hooked my button onClick to refreshClicked(View view) method.
This method is under my MainActivity.java and I'm trying to get the Button with id refresh from tab_1.xml layout but the button text is not updating.
Thanks!
You seems to inflate a layout but never attach it to a parent view as the ViewGroup parameter is null. Then this layout inflated must not even been displayed anywhere.
If the button b already exists, no need to inflate the layout and retrieve the button form there, it will a different button.
Just retrieve the button from the actual existing layout.