I've managed to create a listview where when if titles are too long the textview will marquee continuously, however when I scroll to the bottom of the listview the text will stop marqueing and will only start up again if it goes out of view and then comes back into view again.
The same problem occurs when I use a searchview to populate a list view whereby the row has to go out of view and then back into view before the text starts marqueing.
Here is the XML:
<?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:orientation="vertical"
android:background="#ebebeb"
android:clickable="true">
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/searchView"
android:iconifiedByDefault="false"
android:imeOptions="actionSearch"
android:actionViewClass="android.support.v7.widget.SearchView"
android:focusable="false"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/searchedRecipesLSTV"
android:layout_gravity="center_horizontal"
android:focusableInTouchMode="true"
android:focusable="true"/>
</LinearLayout>
Here is the Java:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View recipeLayout = inflater.inflate(R.layout.search_recipe, container, false);
sView = (SearchView) recipeLayout.findViewById(R.id.searchView);
searchRecipesLSTV = (ListView) recipeLayout.findViewById(R.id.searchedRecipesLSTV);
//sView.requestFocusFromTouch();
sView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
new getJSON().execute(query); //Parse JSON and populate listview.
sView.clearFocus();
searchRecipesLSTV.requestFocus();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (sView.getQuery().length() == 0) {
}
return false;
}
});
return recipeLayout;
}
Here is the Adapter getView TextView specific:
holder.recipeTitle.setText(recipeList.get(position).getRecipeTitle());
holder.recipeTitle.setSelected(true);
holder.recipeTitle.requestFocus();
Finally heres the xml for each row in the listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ImageView
android:layout_width="135dp"
android:layout_height="120dp"
android:id="@+id/recipepic_search"
android:src="@drawable/lillie"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/recipeTitle_tv_search"
android:gravity="center_horizontal"
android:textSize="30sp"
android:layout_marginTop="0dp"
android:scrollHorizontally = "true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"/>
</LinearLayout>
Any help is appreciated, I've tried searching for refreshing focus on listview, programatically scrolling to the bottom and then to the top etc. I'm out of ideas. Thanks!