Android textview inside gridview - android

I put a textview inside the header of a gridview but if I need to scroll the textview it not scroll, instead scroll the gridview.
This is the code:
<GridWithHeader
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gridWithHeader"
android:numColumns="2"
android:focusableInTouchMode="true"
android:nestedScrollingEnabled="true"
android:focusable="true" />
And this is the content of header
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:id="#+id/row_2"
android:weightSum="1">
<TextView
android:id="#+id/text_header_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
where is the error or how can I solve the problem?

try to delete from "GridWithHeader" android:focusableInTouchMode and android:focusable="true" and add them to you Textview like this:
<TextView
android:id="#+id/text_header_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:fadeScrollbars="false"
android:scrollbars="vertical" >

Related

How to make Android textview selectable and scrolled to bottom (by default)?

I have a textview which text must be selectable textView.setTextIsSelectable(true) and scrollable to bottom by default textView.setMovementMethod(ScrollingMovementMethod.getInstance()).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorScreenBackground"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.xxxx.xxxx.MainActivity"
tools:showIn="#layout/activity_main"
android:orientation="vertical"
android:weightSum="100">
<TextView
android:id="#+id/result"
android:scrollbars = "vertical"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
android:elevation="8dp"
android:textIsSelectable="true"
android:gravity="bottom"
android:background="#color/white"
android:padding="5dp"
android:focusable="true"
android:fastScrollEnabled="true"
android:fastScrollAlwaysVisible="true"
android:scrollbarSize="7dip"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium" />
<androidx.core.widget.NestedScrollView
android:id="#+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="60"
android:background="#color/gray_background"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
tools:listitem="#layout/recyclerview_item"
android:background="#color/gray_background"
/>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
The problem is that the setMovementMethod disable the textview selectability.
How to solve this?
NB: The principal feature required here is that not only the textview must be scrollable, but it must also appeared initially scrolled to bottom by default, and this is provided by the setMovementMethod(ScrollingMovementMethod.getInstance()), according to How to get the Android TextView to scroll down to the end automatically.
Put your text view inside an scroll view in your xml
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40">
<TextView
android:id="#+id/textView"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp"
android:textIsSelectable="true"
android:gravity="bottom"
android:background="#color/white"
android:padding="5dp"
android:text="#string/dummy"
android:focusable="true"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium" />
</ScrollView>
Then do this in your class
//This will scroll to bottom
ScrollView scrollView=findViewById(R.id.scrollView);
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});

UP DOWN Focus Handling between TextView and VerticalGridView

I have a xml file which contains TextView and Leanback VerticalGridView. Left/right/down focus is working fine, but then I can't refocus TextView from VerticalGridItem.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/live_category_header_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/roboto_medium_500"
android:text="#string/str_dashboard_live_tv"
android:textColor="#color/common_text_color"
android:textSize="#dimen/live_category_header_text_size"
android:focusable="true"/>
</RelativeLayout>
<com.multiiptv.m3u.xstream.views.LiveVerticalGridView
android:id="#+id/live_category_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/live_category_lr_margin"
android:clipToPadding="false"
android:layout_marginTop="#dimen/live_category_header_grid_margin_tb"
android:layout_marginBottom="#dimen/live_category_header_grid_margin_tb"
android:layout_marginEnd="#dimen/live_category_lr_margin" />
</LinearLayout>
Try adding the following statements to the TextView element:
android:focusable="true"
android:focusableInTouchMode="true"
app:focusOutEnd="true"
app:focusOutFront="true"
If that does not work, please post your presenter code.

Android Child Views inside FrameLayout are Clickable ,How to disable the click of frameLayout child?

when i click the textview its opens the list item popup activity but i set textview android:clickable="false" is not working so how to i disable the click of FrameLayout Child views
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:clickable="true"
android:fadingEdge="none"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="vertical">
<TextView
android:id="#+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:text="Text"/>
</LinearLayout>
</FrameLayout>
As you want TextView to scroll with ListView as last time the best way is to add that View as footer of the ListView
TextView mFooterTextView = new TextView(mContext);
listView.addFooterView(footerView);
and your XML will be
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:clickable="true"
android:fadingEdge="none"/>
</FrameLayout>

how to fix button at end of Listview item are completed?

<ListView
android:id="#+id/listContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:headerDividersEnabled="true"
android:footerDividersEnabled="true"
android:dividerHeight="10dp"
android:background="#drawable/background"
android:divider="#drawable/background"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:fastScrollEnabled="true"
android:scrollingCache="true"
>
</ListView>
<Button
android:id="#+id/btnContactPostYourEnquiry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="POST YOUR ENQUIRY"
android:background="#drawable/contact_post"
android:textColor="#color/White"
android:layout_margin="10dp"
android:layout_below="#+id/listContact"/>
I am try to display the PastEnqury Button at the end of listview not the end of screen but output is only listview is display button is not display if list item is more i.e listview have to scroll
I am writting this code in Relative Layout
Just use the Button as your ListView Footer. This way, it will be part of your ListView and you can scroll down to it.
Put it in relative layout eg is given in code below android:layout_above="#+id/linear" this will put your listview above other layout ,just replace ExpandableListView with ListView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="horizontal" >
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:layout_above="#+id/linear"
android:groupIndicator="#null" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:weightSum="1"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>
Programetically set the height of list view
for e.g.
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, your_array.size() * 120);
nd in xml add button bellow listview in linear layout
I am solve the problem by adding List Footer View
layout_contact_list.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_vertical"
android:layout_marginBottom="#dimen/action_button" >
<ListView
android:id="#+id/listContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:divider="#drawable/background"
android:dividerHeight="10dp"
android:fastScrollEnabled="true"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scrollingCache="true" >
</ListView>
contact_footer_view.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/btnContactPostYourEnquiry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="POST YOUR ENQUIRY"
android:background="#drawable/contact_post"
android:textColor="#color/White"
android:layout_margin="10dp"
android:padding="10dp"
android:layout_gravity="center_horizontal"
/>
mainActivity.java
ListView list_Contact=(ListView)findViewById(R.id.listContact);
FrameLayout footerLayout = (FrameLayout) getLayoutInflater().inflate(R.layout.contact_footer_view,null);
Button btnPostYourEnquiry = (Button) footerLayout.findViewById(R.id.btnContactPostYourEnquiry);
list_Contact.addFooterView(footerLayout);

Scroll PullToRefreshScrollview automatically in android

I have a Listview, FrameLayout inside PullToRefreshScrollview. And I'm loading a fragment into framelayout. Data is loading into listview using lazy adapter. I'm able to see the fragment/framelayout while listview is loading. But Scrollview is automatically scrolling to the postion of listview after data is loaded into listview and framelayout is not visible. How can I scroll the scrollview to top? Please help me. Thanks in advance
<?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="match_parent"
android:background="#color/app_bg"
android:orientation="vertical" >
<com.handmark.pulltorefresh.library.PullToRefreshScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/ptrScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:paddingBottom="5dp"
ptr:ptrMode="pullUpFromBottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<com.xxxx.yyyy.CustomListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_bg"
android:focusable="false" />
<ProgressBar
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</LinearLayout>
Here is the aproach I took
Lets say you have a reference to the PullToRefreshScrollView like so
PullToRefreshScrollView myRefreshScrollView = (PullToRefreshScrollView)findViewById(R.id. ptrScrollView);
To get the ACTUAL ScrollView object you need to call getRefreshableView() like so
ScrollView myScrollView = myRefreshScrollView.getRefreshableView();
and then scroll this object
myScrollView.scrollTo(0,0);
or
myScrollView.smoothScrollTo(0,0)
There are 2 teps to make it works:
you should set android:smoothScrollbar="true" in layout xml :
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="#+id/news_list_listView_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EEE"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:dividerHeight="5dp"
android:layout_marginTop="2dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:smoothScrollbar="true"/>
and Then,
myRefreshScrollView.getRefreshableView().smoothScrollToPosition(lastScollCount);

Categories

Resources