I am trying to display the text 2 columns in dynamic rows depending on the data gotten. Below are my code of the adapter and xml file. I am not sure where I have done wrong or how should i do it.
public class BlogAdapter extends ArrayAdapter<String>{
private final Context context;
private final String[] values;
public BlogAdapter(Context context, String[] values) {
super(context, R.layout.fragment_blogs_list_item, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.fragment_blogs_list_item, null);
}
TextView txtTitle = (TextView) convertView.findViewById(R.id.gridView1);
txtTitle.setText(values[position]);
// Change icon based on name
//String s = values[position];
//System.out.println(s);
return convertView;
}
}
xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<GridView
android:id="@+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="50dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
No comments:
Post a Comment