在我的项目中,我必须显示报告列表,因此Activity
我编写了以下代码:
super.onCreate(savedInstanceState);
setContentView(R.layout.report_full);
List<Employee> data = new ArrayList<Employee>();
Employee eg=new Employee();
ListView li=(ListView)findViewById(R.id.report_list);
Intent myIntent = getIntent(); // this is just for example purpose
Bundle b=myIntent.getExtras();
Log.i("User Report", b.toString());
Toast.makeText(getApplicationContext(), "User Report", Toast.LENGTH_LONG).show();
if(b !=null) {
String username = b.getString("username");
String userid = b.getString("userid");
String startdate = b.getString("startdate");
String enddate = b.getString("enddate");
String mode=b.getString("mode");
Log.i("LOOP", userid+"-"+startdate+"-"+enddate+"-"+mode);
data=eg.getReports(username, userid, startdate, enddate,mode);
Log.i("Get Report",data.toString());
li.setAdapter(new UserReportArrayadapter(this, data));
}
在UserReportArrayadapter.java
我写下面的代码:
private LayoutInflater inflater;
private List<Employee> data;
public UserReportArrayadapter(Context context, List<Employee> objects) {
super(context, R.layout.list_time_mode_report, objects);
Log.i("User Report by HoursAdapter","Inside constructor");
inflater = LayoutInflater.from(context);
this.data = objects;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Log.i("User Report ","Inside getView");
//if it's not create convertView yet create new one and consume it
if(convertView == null){
//instantiate convertView using our employee_list_item
convertView = inflater.inflate(R.layout.list_time_mode_report, null);
//get new ViewHolder
holder =new ViewHolder();
//get all item in ListView item to corresponding fields in our ViewHolder class
holder.project=(TextView)convertView.findViewById(R.id.time_entry_1);
holder.hours=(TextView)convertView.findViewById(R.id.time_entry_2);
//set tag of convertView to the holder
convertView.setTag(holder);
}
//if it's exist convertView then consume it
else {
holder =(ViewHolder) convertView.getTag();
}
//set data to holder
Log.i("User Report by HoursAdapter:data",data.get(position).getData());
holder.project.setText(data.get(position).getData());
holder.hours.setText(data.get(position).getNo_of_hrs());
return convertView;
}
//ViewHolder class that hold over ListView Item
static class ViewHolder{
TextView hours;
TextView project;
}
在日志中,仅"User Report"
显示"Inside getView"
。构造函数被调用但getView()
未被调用。在运行此应用程序时,屏幕上没有显示任何项目。为什么会这样?
还有我的 report_full.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://xyz.com"
android:background="#000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:background="@drawable/col_bg_top"
android:id="@+id/report_title"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="50sp">
</RelativeLayout>
<!-- WHITE LINES -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1sp"
android:orientation="vertical"
android:id="@+id/white_line_top"
android:layout_below="@+id/report_title">
</LinearLayout>
<!-- MAIN LIST VIEW -->
<ListView
android:layout_below="@+id/report_list"
android:id="@+id/report_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/buttons_holder">
</ListView>
<!-- WHITE LINES -->
<LinearLayout
android:background="#9d9d9d"
android:layout_width="fill_parent"
android:layout_height="1sp"
android:orientation="vertical"
android:id="@+id/white_line_bottom"
android:layout_above="@+id/buttons_holder">
</LinearLayout>
<LinearLayout
android:baselineAligned="false"
android:layout_alignParentBottom="true"
android:weightSum="1.0"
android:orientation="horizontal"
android:id="@+id/buttons_holder"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<!-- HOME BUTTON -->
<RelativeLayout
android:background="@drawable/col_bg_highlights"
android:layout_weight="0.33"
android:layout_width="wrap_content"
android:layout_height="62sp" android:padding="3sp">
<TextView
android:id="@+id/txt_btn_home"
android:textColor="#FFFFFF"
android:text="HOME"
android:layout_width="wrap_content"
android:textSize="9sp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
</TextView>
<ImageButton
android:background="#00000000"
android:id="@+id/btn_home"
android:scaleType="fitCenter"
android:layout_height="42dp"
android:layout_width="45sp"
android:padding="3sp"
android:src="@drawable/home_button"
android:layout_below="@+id/txt_btn_home"
android:layout_centerHorizontal="true"
></ImageButton>
</RelativeLayout>
<!-- Dividing Line -->
<RelativeLayout
android:layout_width="1sp"
android:layout_height="62sp"
android:background="#9d9d9d"
></RelativeLayout>
<!-- ACTIVITY BUTTON -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="62sp" android:padding="3sp" android:layout_weight="0.34">
<TextView
android:id="@+id/txt_btn_activity"
android:textColor="#FFFFFF"
android:text="ACTIVITY"
android:layout_width="wrap_content"
android:textSize="9sp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
</TextView>
<ImageButton
android:background="#00000000"
android:id="@+id/btn_activity"
android:scaleType="fitCenter"
android:layout_height="42dp"
android:layout_width="45sp"
android:padding="3sp"
android:src="@drawable/activity_button"
android:layout_below="@+id/txt_btn_activity"
android:layout_centerHorizontal="true"
></ImageButton>
</RelativeLayout>
<!-- Dividing Line -->
<RelativeLayout
android:layout_width="1sp"
android:layout_height="62sp"
android:background="#9d9d9d"
></RelativeLayout>
<!-- REPORTS BUTTON -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="62sp" android:padding="3sp" android:layout_weight="0.34">
<TextView
android:id="@+id/txt_btn_report"
android:textColor="#FFFFFF"
android:text="REPORTS"
android:layout_width="wrap_content"
android:textSize="9sp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
</TextView>
<ImageButton
android:background="#00000000"
android:id="@+id/btn_report"
android:scaleType="fitCenter"
android:layout_height="42dp"
android:layout_width="45sp"
android:padding="3sp"
android:src="@drawable/report_button"
android:layout_below="@+id/txt_btn_report"
android:layout_centerHorizontal="true"
></ImageButton>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>