1- XML modification
Add following tag in your xml. This will assist us in showing list.
android:id="@+id/listProject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector">2- Now add Items in list.Create a new *.xml and add below code in it. This xmls define what you want to show in above image
We are showing only Project name in the list
android:id="@+id/tvProjectName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom ="9dip"
android:text="@string/tvProjectName"
android:textColor="#040404"
android:textSize="20dip"
android:textStyle="bold"
android:typeface="sans"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
3- In project activity java code use below line
// List items
ListView list;
ProjectBinderData adapter = null;
List> projectDataCollection;
HashMap mapSingleProjectDataCollection;
try {
projectDataCollection = new ArrayList
>();
for(int i=0;i{
mapSingleProjectDataCollection = new HashMap();
mapSingleProjectDataCollection.put(KEY_PROJECT_ID, projectInfoList[i].getProperty("projectId").toString()); try {
projectDataCollection = new ArrayList>();
for(int i=0;i{
mapSingleProjectDataCollection = new HashMap();
mapSingleProjectDataCollection.put(KEY_PROJECT_ID, projectInfoList[i].getProperty("projectId").toString());
mapSingleProjectDataCollection.put(KEY_PROJECT_NAME, projectInfoList[i].getProperty("projectName").toString());
projectDataCollection.add(mapSingleProjectDataCollection);
}
//Add to the Arraylist
ProjectBinderData bindingData = new ProjectBinderData(ProjectPageActivity.this,projectDataCollection);
list = (ListView) findViewById(R.id.listProject);
Log.i("BEFORE", "<<------------- before="" setadapter--------------="">>");------------->
list.setAdapter(bindingData);
Log.i("AFTER", "<<------------- after="" setadapter--------------="">>");------------->
// Click event for single list row and send the data to sprint page.
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View view,
int position, long id) {
Intent i = new Intent();
i.setClass(ProjectPageActivity.this, SprintPageActivity.class);
// parameters
i.putExtra("projectId", projectDataCollection.get(position).get(KEY_PROJECT_ID));
i.putExtra("projectViewId", projectViewId);
// start the sample activity
startActivity(i);
}
});
}
catch (Exception ex) {
//Toast.makeText(getApplicationContext(), "System Error Please try after some time !!!!!",Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
mapSingleProjectDataCollection.put(KEY_PROJECT_NAME, projectInfoList[i].getProperty("projectName").toString());
mapSingleProjectDataCollection.put(KEY_CURRENT_SPRINT, "Current Sprint "+projectInfoList[i].getProperty("completedSprint").toString()+"/"+projectInfoList[i].getProperty("totalSprint").toString());
mapSingleProjectDataCollection.put(KEY_TOTAL_SPRINT, projectInfoList[i].getProperty("totalSprint").toString());
mapSingleProjectDataCollection.put(KEY_COMPLETED_SPRINT, projectInfoList[i].getProperty("completedSprint").toString());
mapSingleProjectDataCollection.put(KEY_PROJECT_START_DATE, projectInfoList[i].getProperty("projectStartDate").toString());
mapSingleProjectDataCollection.put(KEY_PROJECT_END_DATE, projectInfoList[i].getProperty("projectEndDate").toString());
mapSingleProjectDataCollection.put(KEY_RAG_STATUS, projectInfoList[i].getProperty("ragStatus").toString());
mapSingleProjectDataCollection.put(KEY_PROJECT_STATUS, projectInfoList[i].getProperty("projectStatus").toString());
projectDataCollection.add(mapSingleProjectDataCollection);
}
//Add to the Arraylist
ProjectBinderData bindingData = new ProjectBinderData(ProjectPageActivity.this,projectDataCollection);
list = (ListView) findViewById(R.id.listProject);
Log.i("BEFORE", "<<------------- before="" setadapter--------------="">>");------------->
list.setAdapter(bindingData);
Log.i("AFTER", "<<------------- after="" setadapter--------------="">>");------------->
// Click event for single list row and send the data to sprint page.
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View view,
int position, long id) {
Intent i = new Intent();
i.setClass(ProjectPageActivity.this, SprintPageActivity.class);
// parameters
i.putExtra("projectId", projectDataCollection.get(position).get(KEY_PROJECT_ID));
i.putExtra("projectViewId", projectViewId);
// start the sample activity
startActivity(i);
}
});
}
catch (Exception ex) {
//Toast.makeText(getApplicationContext(), "System Error Please try after some time !!!!!",Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
4- Create a new class ProjectBinderData
public class ProjectBinderData extends BaseAdapter {
static final String KEY_PROJECT_ID = "KEY_PROJECT_ID";
static final String KEY_PROJECT_NAME= "KEY_PROJECT_NAME";
LayoutInflater inflater;
List> projectDataCollection;
ViewHolder holder;
public ProjectBinderData() {
// TODO Auto-generated constructor stub
}
public ProjectBinderData(Activity act, List> map) {
this.projectDataCollection = map;
inflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
// return idlist.size();
return projectDataCollection.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null){
vi = inflater.inflate(R.layout.list_project, null);
holder = new ViewHolder();
holder.tvProjectName = (TextView)vi.findViewById(R.id.tvProjectName); // Project name
vi.setTag(holder);
}
else{
holder = (ViewHolder)vi.getTag();
}
// Setting all values in listview
holder.tvProjectName.setText(projectDataCollection.get(position).get(KEY_PROJECT_NAME));
return vi;
}
/*
*
* */
static class ViewHolder{
TextView tvProjectName;
}
}