Android add data to custom layout and scrollview



in my application i have simple layout to filled by any data with class structure. after add items into that i want to add this layout into scroll view. adding layout to scrollview is successfull but i can not set data to custom layout. for example this is my custom layout to set data :


tile.xml:



<LinearLayout
xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/drop_shadow">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="30dp" android:minHeight="100dp" android:background="#eee">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="New Text"
android:id="@+id/username"/>
</LinearLayout>
</LinearLayout>


Class data structure:



public class SubjectStructure {
public String username;
public String topic;
public String description;
public String avatar;
public String sender;
public Integer grade;
public Integer type;
public String date;
}


now i want to fill tile.xml and add that into this below layout:


fragment_home.xml:



<ScrollView xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#F1F1F1">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/scrollView1">
</LinearLayout>
</ScrollView>


my code is this : public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {



View rootView = inflater.inflate( R.layout.fragment_home, container, false);
scrollView = (LinearLayout) rootView.findViewById ( R.id.scrollView1 );

for(SubjectStructure SS: G.subject_items){
LinearLayout newLL = new LinearLayout( G.context );
TextView newTV = new TextView( G.context );
newTV.setText ( SS.topic );
newLL.addView(newTV);

LayoutInflater in = (LayoutInflater) G.context.getSystemService(G.context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.tile, null);
scrollView.addView(view);
}
return rootView;
}


in this code i can add tile.xml to fragment_home.xml . but i can not setText SS.topic to tile.xml. SS.topic is not null and have data. how to resolve this problem?


No comments:

Post a Comment