Saturday, 7 September 2013

how to put a custom view into a custom list view for list fragment

how to put a custom view into a custom list view for list fragment

I am having a custom layout for the list fragment. Inside that custom list
layout, i want to put another custom view (which do drawing things). So my
question is: how to add another view to convertView in method getView().
Here is my getView method:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView =
getActivity().getLayoutInflater().inflate(R.layout.trainings_custom_layer_listfragment,
null);
}
Product p = getItem(position);
//references to text view and image view goes here
//begin to work with custom view
StarView sv = (StarView) convertView.findViewById(R.id.star_view);
return convertView; }
Here is my layout:
<ImageView android:id="@+id/imageview_product_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="mini photo" />
<TextView android:id="@+id/textview_training_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/imageview_product_category"
android:textColor="@color/text_color_white" />
<TextView android:id="@+id/textview_training_location"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/imageview_product_category"
android:layout_below="@id/textview_training_title"
android:textColor="@color/text_color_white" />
<TextView android:id="@+id/textview_training_datetime"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/imageview_product_category"
android:layout_below="@id/textview_training_location"
android:textColor="@color/text_color_white" />
<TextView android:id="@+id/textview_training_cost"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/imageview_product_category"
android:layout_below="@id/textview_training_datetime"
android:textColor="@color/text_color_white" />
<TextView android:id="@+id/textview_training_registrationenddate"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/imageview_product_category"
android:layout_below="@id/textview_training_cost"
android:textColor="@color/text_color_white" />
<jacky.practice.view_custom.StarView
android:id="@+id/star_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageview_product_category"
android:layout_below="@id/textview_training_registrationenddate"/>

No comments:

Post a Comment