Could anyone help me how to scroll textview horizontally in list view using marquee text. I am using marquee text in simple textview its working fine when same concept I use in listview textview its not working/scrolling please help me.! Thanks
Here is my xml single list item file
<br><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="15dp"
android:layout_height="match_parent">
<TextView
android:layout_width="340dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:id="@+id/list_text"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#cc0000"
android:singleLine="true" />
</LinearLayout>
Here is my Java file
LayoutInflater inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View child = inflater.inflate(R.layout.list_item, null);<br>
TextView text=(TextView)child.findViewById(R.id.list_text);<br>
text.setSelected(true);<br>
arrayAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_item,R.id.list_text, s);<br>
listView.setAdapter(arrayAdapter);
In your code, you are inflated a view that is same type of the item view but that is not the item view. To modify the item view, you need to override the getView() method of the adapter. Try the code below:
arrayAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_item, R.id.list_text, s){
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
convertView = super.getView(position, convertView, parent);
TextView tv = convertView.findViewById(R.id.list_text);
tv.setSelected(true);
return convertView;
}
};
list.setAdapter(arrayAdapter);