Hello, I am doing a binding and I have only one of the properties of my Model that are appearing in my listView. Here is the code:
Adapter:
public class ProjectAdapter extends ArrayAdapter<Project>{
private List<Project> _projects;
public ProjectAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
// TODO Auto-generated constructor stub
}
public ProjectAdapter(Context context, List<Project> projects) {
super(context, R.layout.project_list_view, projects);
this._projects = projects;
}
@SuppressLint("InflateParams") @Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.project_list_view, null, true);
}
Project project = this._projects.get(position);
if (project != null) {
TextView txtPName = (TextView) v.findViewById(R.id.txtProjectName);
TextView txtCName = (TextView) v.findViewById(R.id.txtCustomerName);
TextView txtCEmail = (TextView) v.findViewById(R.id.txtCustomerEmail);
TextView txtCPhone = (TextView) v.findViewById(R.id.txtCustomerPhone);
TextView txtWTime = (TextView) v.findViewById(R.id.txtWorkingTime);
TextView txtAMoney = (TextView) v.findViewById(R.id.txtAmountMoney);
if (txtPName != null) {
txtPName.setText(project.getName());
}
if (txtCName != null) {
txtCName.setText(project.getCustomerName());
}
if (txtCEmail != null) {
txtCEmail.setText(project.getCustomerEmail());
}
if (txtCPhone != null) {
txtCPhone.setText(project.getCustomerPhone());
}
if (txtWTime != null) {
txtWTime.setText(project.getWorkingTime().toString());
}
if(txtAMoney != null){
txtAMoney.setText(project.getAmountMoney().toString());
}
}
return v;
}
}
Model:
public class Project {
public int Id;
public String Name;
public String CustomerName;
public String CustomerEmail;
public String CustomerPhone;
public Float WorkingTime = null,
AmountMoney = null;
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCustomerName() {
return CustomerName;
}
public void setCustomerName(String customerName) {
CustomerName = customerName;
}
public String getCustomerEmail() {
return CustomerEmail;
}
public void setCustomerEmail(String customerEmail) {
CustomerEmail = customerEmail;
}
public String getCustomerPhone() {
return CustomerPhone;
}
public void setCustomerPhone(String customerPhone) {
CustomerPhone = customerPhone;
}
public Float getWorkingTime() {
return WorkingTime;
}
public void setWorkingTime(Float workingTime) {
WorkingTime = workingTime;
}
public Float getAmountMoney() {
return AmountMoney;
}
public void setAmountMoney(Float amountMoney) {
AmountMoney = amountMoney;
}
}
main_page.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="universo91.freelancecalculator.MainPageActivity" >
<ListView
android:id="@+id/listProject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtMProject"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp" >
</ListView>
<TextView
android:id="@+id/txtMProject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/lbl_page_title"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
project_list_view.xaml (should be every item in my listview):
<?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:orientation="horizontal" >
<TextView
android:id="@+id/txtProjectName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
<TextView
android:id="@+id/txtCustomerName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
<TextView
android:id="@+id/txtCustomerEmail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
<TextView
android:id="@+id/txtCustomerPhone"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
<TextView
android:id="@+id/txtWorkingTime"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
<TextView
android:id="@+id/txtAmountMoney"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
/>
</LinearLayout>
Output:
Please note that there are no other fields other than ProjectName.