mardi 26 mai 2015

Capture TextView's Layout from xml and duplicate it programmatically

I want to add programmatically a certain amount of TextView in a FrameLayout, but I want the TextViews to have a pre-defined layout that I've specified in a xml file.

frag_content_tours:

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <TextView android:id="@+id/tours" android:clickable="true"
        android:background="?android:selectableItemBackground"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="Lorem ipsum"/> 
</RelativeLayout>

Here the Fragment class:

public static class ContentTours extends Fragment{
    public static String TOUR_NAME= "tour_info";
    View view = getView(); TextView contentTour;
    Context context;
    public ContentTours(Context cntxt){
        this.context=cntxt;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.frag_content_tours, container, false);
        contentTour = (TextView) view.findViewById(R.id.tours);
        contentTour.setText(getArguments().getString("1"));

        Layout st = contentTour.getLayout();//?

        return view;
    }
}

Is it possible to append a series of TextView with the exact specified layout, without specifying every single parameter inside Fragment class?

Aucun commentaire:

Enregistrer un commentaire