Wednesday, 28 August 2013

ListView not inflating

ListView not inflating

Good day to all.
I am currently working on a customized ListView which is not inflating (is
not becoming visible) inside the activity.
Below are the xml and ListView adapter classes.
main.xml
<LinearLayout
android:id="@+id/llListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:layout_below="@+id/rlFirstRow">
<ListView
android:id="@+id/lvErrorsReport"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/border"/>
</LinearLayout>
listview_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/llError"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<TextView
android:id="@+id/txtErrorInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textStyle="bold"
android:textSize="20dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/llStatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/llError">
<TextView
android:id="@+id/txtStatus"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Status: "/>
<TextView
android:id="@+id/txtStatusInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textStyle="italic"/>
</LinearLayout>
<LinearLayout
android:id="@+id/llMaterials"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/llStatus">
<TextView
android:id="@+id/txtMaterials"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Materials: "/>
<TextView
android:id="@+id/txtMaterialsInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textStyle="italic"/>
</LinearLayout>
<LinearLayout
android:id="@+id/llButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/llMaterials">
<Button
android:id="@+id/btnShowMaterials"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Materials"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
BaseAdapter class
public class RepairReportListViewAdapter extends BaseAdapter
{
ArrayList<String> errors;
ArrayList<String> statuses;
ArrayList<Boolean> materials;
Context mContext;
LayoutInflater inflater;
public RepairReportListViewAdapter(Context context, ArrayList<String> err,
ArrayList<String> stat, ArrayList<Boolean> mat)
{
this.mContext = context;
this.errors = err;
this.statuses = stat;
this.materials = mat;
inflater =
(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return 0;
}
@Override
public Object getItem(int position)
{
return null;
}
@Override
public long getItemId(int position)
{
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if(convertView == null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.repairreport_listview, null);
holder.error = (TextView)convertView.findViewById(R.id.txtErrorInfo);
holder.status =
(TextView)convertView.findViewById(R.id.txtStatusInfo);
holder.material =
(TextView)convertView.findViewById(R.id.txtMaterialsInfo);
holder.showMaterials =
(Button)convertView.findViewById(R.id.btnShowMaterials);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.error.setText(this.errors.get(position).toString());
holder.status.setText(this.statuses.get(position).toString());
if(this.materials.get(position) == true)
{
holder.material.setText("Materials where used to fix this error.
Click on the button below to view the materials.");
holder.showMaterials.setVisibility(Button.VISIBLE);
holder.showMaterials.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//LATER
}
});
}
else
{
holder.material.setText("No materials where used to fix this
error.");
}
return convertView;
}
static class ViewHolder
{
TextView error;
TextView status;
TextView material;
Button showMaterials;
}
}
I've already tried changing the layouts as suggested here but the ListView
is still not revealed.
Any ideas why it is not showing? Sorry for the code dump but I really
cannot figure out what the heck is going on.
P.S. I did set the adapter to the ListView in the main activity.
adapter = new RepairReportListViewAdapter(this, errorNames, statuses,
materialsInUse);
lvErrors.setAdapter(adapter);

No comments:

Post a Comment