Recently I asked a question on how to have one style for a TextView and display it multiple times for other texts as well. The solution was, to create an XML-Layout where I design the textview and then use an ArrayAdapter to fill it with contents. I'm using the ArrayAdapter in a fragment because I have multiple fragments that replace the main fragment dependent on the menu click.
But I'm stuck. I don't really know how to achieve that. I'm writing all my values into an array and then I'm assigning them to my ArrayAdapter. I have seen plenty solutions, but none of them fixed my problem and they all used an other way.
This is the xml of the fragment
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ScrollView
android:id="@+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.03" >
<TextView
android:id="@+id/sources"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="20px" >
</TextView>
</ScrollView>
</RelativeLayout>
The TextView is the textview I want to populate. There is no style yet, I'm doing it just for test purposes. Now I did this in the Fragment.
This is my onCreateView method
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
StrictMode.setThreadPolicy(policy);
View rootView = inflater.inflate(R.layout.main_fragment, null);
RelativeLayout ll = new RelativeLayout(getActivity());
ScrollView sv = new ScrollView(getActivity());
ArrayAdapter<String> sourceAdapter = new ArrayAdapter<String>(getActivity(), R.id.mainScrollView, R.id.sources, sourceArr);
return rootView;
}
sourceArr
is the array with the contents. How exactly do I assign all values to the TextView so it gets displayed multiple times? Thanks