I generated a custom grid view, by passing to my adapter an ArrayList with Arrays of Strings.
Everything is working fine, my gridView is generated as I want (every String Array represents a column in my gridView).
The only problem is, that I can not see vertical separators in the gridview, only the horizontal ones are visible. I really need the vertical separators as well. Please help me with this.
Here is my xml
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnWidth="130dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth"/>
Here is my code
ArrayList
list = new ArrayList ();
String [] id = {"IDs", "S001","S002","S003","S004","S005","S006","S007"};
String [] name = {"NAMES", "Rohit","Rahul","Ravi","Amit","Arun","Anil","Kashif"};
String [] products = {"Products", "Bear","Tea","Apple","Food","Color","Program","Telephone"};
String [] stuff = {"Stuffs", "Stuff_01","Stuff_02","Stuff_03","Stuff_04","Stuff_05","Stuff_06","Stuff_07"};
list.add(id);
list.add(name);
list.add(products);
list.add(stuff);
gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new DataAdapter(this, list));
My Custom Adapter
public class DataAdapter extends BaseAdapter {
Context mContext;
private ArrayListlist;
private LayoutInflater mInflater;
private ArrayListlayouts = new ArrayList ();
public DataAdapter(Context c, ArrayListmyList)
{
mContext=c;
mInflater = LayoutInflater.from(c);
list = myList;
}
@Override
public int getCount()
{
return list.get(0).length;
}
@Override
public Object getItem(int position)
{
return layouts.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout view;
if (convertView == null) {
view = new LinearLayout(mContext);
for (int i = 0; i < list.size(); i++) {
TextView tv = new TextView(mContext);
tv.setLayoutParams(new GridView.LayoutParams(80, 30));
view.addView(tv);
}
layouts.add(position, view);
}
else {
view = (LinearLayout) convertView;
}
for (int i = 0; i < view.getChildCount(); i++) {
TextView tv = (TextView) view.getChildAt(i);
tv.setText(list.get(i)[position]);
}
view.setBackgroundColor(Color.BLUE);
return view;
}
}
.
stackoverflow.comm
No comments:
Post a Comment