Well i have using a gridview with customized adapter and textViews for rows. Below are the codes:
ScheduleListActivity.java
public class ScheduleListActivity extends android.app.Activity
{
GridView gridView;
ScheduleModel aSchedulObj;
ArrayList<ScheduleModel> schedul_arr;
GetCityFromAsync cityAsync;
AdapterScheduleList myAdapter;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_schedule);
schedul_arr = new ArrayList<ScheduleModel>();
gridView = (GridView) findViewById(R.id.lst_all_schedule);
cityAsync =new GetCityFromAsync();
cityAsync.execute();
}
private class GetCityFromAsync extends AsyncTask<Void, Void, String>
{
Context context;
@Override
protected void onPreExecute()
{ super.onPreExecute(); }
@Override
protected String doInBackground(Void... arg0)
{ return null; }
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
try {
aSchedulObj = new ScheduleModel("Shaon", "23-Sep-2015", "12:58", "1:00", "92.800", "101.02", "Mirpur, kazipara");
schedul_arr.add(aSchedulObj);
aSchedulObj = new ScheduleModel("aaaa", "bbb", "12:58", "1:00", "92.800", "101.02", "rokeya sharani, kazipara");
schedul_arr.add(aSchedulObj);
aSchedulObj = new ScheduleModel("xxx", "yyy", "1:58", "2:00", "55.00", "60.55", "panthapath, kalabagan");
schedul_arr.add(aSchedulObj);
myAdapter = new AdapterScheduleList(getApplicationContext(), schedul_arr);
gridView.setAdapter(myAdapter);
}
catch (Exception e) {
e.printStackTrace(); }
}
}
}
activity_view_schedule.xml layout for ScheduleListActivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFF99"
android:orientation="vertical"
android:padding="2dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#7D7D7D"
android:orientation="horizontal"
android:weightSum="6" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.45"
android:background="#7D7D7D"
android:padding="3dp"
android:paddingLeft="10dp"
android:text="Client Name"
android:textColor="#FF9900"
android:textSize="14sp"
android:typeface="serif" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.35"
android:background="#7D7D7D"
android:padding="3dp"
android:paddingLeft="10dp"
android:text="Schedule Date"
android:textColor="#FF9900"
android:textSize="14sp"
android:typeface="serif" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.9"
android:background="#7D7D7D"
android:padding="3dp"
android:paddingLeft="10dp"
android:text="Start Time"
android:textColor="#FF9900"
android:textSize="14sp"
android:typeface="serif" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.9"
android:background="#7D7D7D"
android:padding="3dp"
android:paddingLeft="10dp"
android:text="End Time"
android:textColor="#FF9900"
android:textSize="14sp"
android:typeface="serif" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.4"
android:background="#7D7D7D"
android:padding="3dp"
android:paddingLeft="10dp"
android:text="Location Address"
android:textColor="#FF9900"
android:textSize="14sp"
android:typeface="serif" />
</LinearLayout>
<GridView
android:id="@+id/lst_all_schedule"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:listSelector="@android:color/transparent"
android:numColumns="1"
android:stretchMode="columnWidth" >
</GridView>
</LinearLayout>
Adapter for gridview
public class AdapterScheduleList extends BaseAdapter {
Context _adapterContext;
ArrayList<ScheduleModel> sch_arr;
public AdapterScheduleList(Context context,
ArrayList<ScheduleModel> scheduls) {
_adapterContext = context;
this.sch_arr = scheduls;
}
public void updateList() { notifyDataSetChanged(); }
@Override
public int getCount() { return sch_arr.size(); }
@Override
public ScheduleModel getItem(int position) { return sch_arr.get(position); }
@Override
public long getItemId(int position) {return Long.valueOf(sch_arr.get(position).getScheduleID()); }
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) _adapterContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.listitem_schedule, parent,false);
final ScheduleModel _aSchdl = (ScheduleModel) getItem(position);
TextView txtVwName = (TextView) rowView.findViewById(R.id.grid_item_name);
txtVwName.setText(_aSchdl.getClientName());
TextView txtVwDate = (TextView) rowView.findViewById(R.id.grid_item_date);
txtVwDate.setText(String.valueOf(_aSchdl.getScheduleDate()));
TextView txtVwStartTime = (TextView) rowView.findViewById(R.id.grid_item_label_starttime);
txtVwStartTime.setText(String.valueOf(_aSchdl.getScheduleStartTime()));
TextView txtVwEndTIme = (TextView) rowView.findViewById(R.id.grid_item_endTime);
txtVwEndTIme.setText(String.valueOf(_aSchdl.getScheduleEndTime()));
TextView txtVwAddress = (TextView) rowView.findViewById(R.id.grid_item_address);
txtVwAddress.setText(String.valueOf(_aSchdl.getScheduleAddress()));
return rowView;
}
}
row items layout - listitem_schedule.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1975A3"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:id="@+id/cityListFromItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/grid_item_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.45"
android:padding="3dp"
android:text="xxx"
android:textColor="#FFFFFF" >
</TextView>
<TextView
android:id="@+id/grid_item_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.35"
android:padding="3dp"
android:text="xxx"
android:textColor="#FFFFFF" >
</TextView>
<TextView
android:id="@+id/grid_item_label_starttime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.9"
android:padding="3dp"
android:text="xxx"
android:textColor="#FFFFFF" >
</TextView>
<TextView
android:id="@+id/grid_item_endTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_weight="0.9"
android:padding="3dp"
android:text="xxx"
android:textColor="#FFFFFF" >
</TextView>
<TextView
android:id="@+id/grid_item_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_weight="1.4"
android:padding="3dp"
android:text="xxx"
android:textColor="#FFFFFF" >
</TextView>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:background="#FFFFCC" />
</LinearLayout>
Now what i need is that borders for rows and columns. How is that possible? As i tried several solutions and failed, so finally had to use a view for underline border.
Please help me out :-)