i have two view
<VideoView
android:id="#+id/player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/lighter_gray"
android:id="#+id/imageView"
/>
I want to select only one view to shown at run time , is there container for them to do the job ?
i searched and found something like viewswitcher ,but i dont want to switch between them i only want to display one of them
You can set video view and image view visibility to gone in xml by adding android:visibility="gone"
and setVisibility to visible in java code based on the requirement or which view you want to show.
If you have hundreds of items in list.
You can simply managed by list adapter with one own type field and create custom adapter with the list and switch the views on each position as per your requirement.
Related
I have been given the task to implement a feature on Mobile application. Previously I had no experience with Android nor Java.
What I need is one screen (one fragment) to display two lists of events with uneven number of members one after another, let's call them ListX and ListY.
I've made layout containing two RecyclerViews and two labels (one label to act as header for each of recycler views).
It is working as it is now and I have events displayed, but ListX is scrollable even though its layout_height is set to wrap_content (only 6 items displayed at the time) while ListY is not scrollable and is displaying all events in collection.
What I need is all items from ListX displayed in first RecyclerView (without scroll), and after that ListY displayed in second RecyclerView without scroll too.
Layout:
<FrameLayout
android:id="#+id/resultsView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/label_daily" />
<android.support.v7.widget.RecyclerView
android:id="#+id/list_daily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/label_daily"
tools:listitem="#layout/fragment_timetracking_event_item" />
<TextView
android:id="#+id/label_unfinished" />
<android.support.v7.widget.RecyclerView
android:id="#+id/list_unfinished"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/label_unfinished"
tools:listitem="#layout/fragment_timetracking_event_item" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
As you can see from XML both RecyclerViews have layout_height set to wrap_content yet first RecyclerView is not obeying.
Here is sketch of how it should look like
Is there any way to put both lists in one RecyclerView and make custom separators? Or any other way to anchor beginning of one list to the end of the other and make them show all items without scroll?
I hope to get help here.
You don't need 2 recyclerViews, you can achieve using single recylcerView.
You should read about getItemViewType & using same in bindViewHolder & createViewHolder
You can specify these three types
Header
DailyItem
FinishItem
Create your list like this
add Daily HEADER
add Daily ITEMS
add Unfinished HEADER
add Unfinished ITEMS
Now you can render both lists in single recyclerview
Your problem
...other way to anchor beginning of one list to the end of the other and make them show all items without scroll?
has a simple solution without rewriting your code to the one RecycleView - just put android.support.v4.widget.NestedScrollView instead of ScrollView in your xml layout. It seems to be a bug in the ScrollView widget, which is fixed in android.support.v4.widget.NestedScrollView.
P.S. After solving this problem you will face with other problem - Android RecycleView scrolls with no momentum, which is resolved in "RecyclerView within NestedScrollView Scrolling Issue". It is fine only for short item list in RecycleView because as it is mentioned in comments to above article
This is not a good solution since disabling nested scrolling will disable cell reuse as well, therefore loading all cells at once.
which will have impact on the memory consumption of your app in the case of long item list.
How to make Grid view with click able grid items and nested views (buttons,Image) by remote(For Android TV)
I just want to click able image and button in grid view item should add to play my list if I navigate on button by Remote navigation not by touch
Thank you!!!
How to navigate through d pad in grid view sub items if grid view item have two sub items image button and another button
It is no difference between touch screen or remote control for methods like onClickListener or etc.
For remote control, you need to focus on the element first, than you can click the element.
I have not use the gridView on TV before, but I have used the recyclerView and scrollView. I think they have same situation.
I've try the default simpleAdapter to create the gridView, and it's no problem with the nested views that I can focus and click each grid items after I set the onItemClickListener to the gridView.
I guest your problem is that the grid item conflicts with the button in the grid item.
To avoid this situation, you need to set android:descendantFocusability="blocksDescendants" for the container of your custom grid item view. It will block the items statement in that parent layout.
If you want the button change in the different statement, you can give the button this parameter: android:duplicateParentState="true".
That will let the button follow it's parent's statement.
By the way, don't forget to set some changes to different statement for the grid items (background changes or etc), or you will not know which grid item you have focused :P.
Hope this will help you :)
PS. The following is the sample code for the custom grid item layout. Maybe the example can help you to understand what I mentioned easily.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:duplicateParentState="true"/>
</LinearLayout>
2015.01.06 23:11 update:
How to navigate through d pad in grid view sub items if grid view item
have two sub items image button and another button
For this case you should not use OnItemClickListener. Instead, you should make your grid item unfocusable and unclickable, and than set OnClickListener for both two buttons.
You can set the parameters in your customize adapter for the gridView. In getView method you can set each of the grid item view just like convertView.focusable(false) and convertView.clickable(false).
After that, you can set the click listener and give the method you want to do for the buttons in adapter.
Don't care about the D-pad action. Actually, D-pad will work automatically if there are elements can be focused.
The key point for this question is the conflict between grid item and its child elements. You could have just one part to be focused: grid item (the parent view), or the buttons (the child views).
I have several edittexts in my view for taking input for a database query .I'm displaying the query results in a list view below the edittextfields. Because there are 7 edittextfields there is not enough space for the listview. I wanted to put all the edittexts in an expandablelistview.
Problem i'm facing is -only the expandablelistview item is shown -the listview doesnt come up at all --i have #android:id/empty and #android:id/list entries ---but nothing comes up
i can't add the listview into the expandablelistview as that is not allowed + since i need both #android:id/empty and #android:id/list to show query results i need a proper list view.
what are my options --? i could ofcourse display the results in a separate window
If you could show the xml you have right now it would be great but the ideas behind it needs to be something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Edit:
Okay so i figured out that for this layout to function correctly you need to set dome weight so that the linearlayout understand what size to give each children. Use:
android:layout_weight="1"
in the listview and the expandablelistview (1 in both means thay will divide space between them)
I am developing an application that needs to pair with other devices through Bluetooth. I was having trouble in order to show the list of paired devices in correct manner. I had also viewed the example in the android api (Bluetooth Chat), but i was having the same problem.
The list of paired devices are to big and then hides a search button that are at the bottom of the list.
My xml code is very the same of the example:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="#+id/listpaired_devices"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title_paired_devices"
android:visibility="gone"
android:background="#666"
android:textColor="#fff"
android:paddingLeft="5dp"
/>
<ListView android:id="#+id/paired_devices"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:layout_weight="1"
/>
<TextView android:id="#+id/list_new_devices"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title_other_devices"
android:visibility="gone"
/>
<ListView android:id="#+id/new_devices"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:layout_weight="2"
/>
<Button android:id="#+id/btscan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/btscan"
/>
</LinearLayout>
But and i can't show the search button at the bottom.
Here my screen:
My Screen
You could see a bit of the button at the bottom of the dialog window.
It's possible to limit the number of rows shown at the listview ? Can anyone tell me how i can fix this problem
Firstly some points about your code:
layout_weight is only meaningful if an object has no size in a certain dimension, that is you set layout_height or layout_width to 0, so this has no effect on your code.
Setting the height of a ListView to wrap_content is pretty meaningless, and even if it works it's bad practice. Use either 'fill_parent' or a definite height.
The button is hidden because, as per the point above, the ListViews you have created have no predefined size so take up as much space as they can, pushing the button off the screen.
So let's think about what you really have there - it's just a single list with a button at the bottom (yes you may have headers or multiple sources of data in there but we'll get onto that).
The following layout will give you a ListView at the top and a Button at the bottom. The ListView will take up any space not being used by the Button. Notice how the Button is defined before the ListView in the layout - this causes Android to calculate how much height the button takes up before considering the ListView. It then gives the ListView the rest of the height available.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="#+id/btscan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="#string/btscan"
/>
<ListView android:id="#+id/all_devices"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/btscan"
android:stackFromBottom="true"
/>
</RelativeLayout>
So that's the layout. Now lets consider the actual content of your list: you have a header, followed by a list of paired devices, followed by another header and then a list of new devices.
You can create this using a single Adapter - Commonsware provides a very good implementation called MergeAdapter but you could code your own. MergeAdapter doesn't directly let you a view (e.g. for the headers) but thankfully Commonsware also provides the SackOfViewsAdapter which allows you to add views to it, and then you can add the SackOfViewsAdapter to the MergeAdapter.
Here is some pseudo-code which should accomplish what is outlined above.
// This is the adapter we will use for our list with ListView.setAdapter
MergeAdapter listAdapter = new MergeAdapter();
// The first header - you'll need to inflate the actual View (myHeaderView1) from some resource
// using LayoutInflater
List<View> firstHeaderViews = new List<View();
firstHeaderViews.add(myHeaderView1);
SackOfViewsAdapter firstHeaderAdapter = new SackOfViewsAdapter(firstHeaderViews)
// Second header
List<View> secondHeaderViews = new List<View();
secondHeaderViews.add(myHeaderView2);
SackOfViewsAdapter secondHeaderAdapter = new SackOfViewsAdapter(secondHeaderViews);
// Now to add everything to the MergeAdapter
// First goes the first header
listAdapter.addAdapter(firstHeaderAdapter);
// Now your first list
listAdapter.addAdapter(firstListAdapter);
// Now your second header
listAdapter.addAdapter(secondHeaderAdapter);
// Now your second list
listAdapter.addAdapter(secondListAdapter);
// Now set the adapter to the list
myList.setAdapter(listAdapter)
The layout produced should look something like this. Note I extended the list to show how it behaves with a list longer than the screen; the button still remains visible. The red box marks the bounds of the screen.
You can limit the number of rows shown at the list view, but not sure if that will really help you in what you want to achieve, because you're hiding information from the user that might be important to him. You can limit the number of rows by limiting the number of items you pass to the listview adapter, or you can set the visibility to 'gone' in the getView method when the list view reaches a certain position (you can check the 'position' parameter of getView()).
However, I would suggest you use only one list view (add a separator for the 'new/other devices' title into the view for a list item, but hide it by default, and then, as already suggested by suri, use headers and footers for the listview (to place the scan button).
I have Created a ListView and set a background image.Everything goes fine except I am unable to click on the right side of the row of ListView.Can anybody help me this.
Below is the xml file...
<ListView
android:layout_width="wrap_content"
android:id="#+id/JSONListView"
android:layout_height="wrap_content"
android:background="#drawable/listbg"
android:focusable="false"
android:cacheColorHint="#00000000"
android:visibility="visible" >
</ListView>
And I am not using any View.
Use the attribute
android:layout_width="match_parent"
and set click listener for items.
I guess you have created your custom adapter. If so, just go to the getView() method of that custom adapter and on the holder instance of that portion of listitem add a onCLickListener.
Provide more info. XML layout, etc.
Im guessing there is a view there or it is not filling the entire width but difficult to say.
Android ListView Activity