I have an app that retrieves data from a webservice in the form of an array. In the getView() of the adapter i set the TextViews to the elements in the array. The array is called recordItem and has various elements one of which is “status”. Status is a String that can be either completed, ncr, or waiting. if i set the TextView in the listview directly with the value completed, ncr or waiting there’s no problem.
I don’t want to display the full string in the textview but rather display a C, NCR or W instead. I have a series of “if statements” that check the array element and then sets the textview to the respective character.
The problem is that no character is being displayed. why?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rotarowlayout, parent,
false);
TextView startTime = (TextView) rowView
.findViewById(R.id.rowstarttime);
TextView duration = (TextView) rowView
.findViewById(R.id.rowduration);
TextView status = (TextView) rowView.findViewById(R.id.rowstatus);
TextView name = (TextView) rowView.findViewById(R.id.rowclientname);
String record = list.get(position).toString();
String[] itemsInRecord = record.split(",");
Log.e(TAG, "itemin record = " + itemsInRecord.length);
String[] recordItem = new String[itemsInRecord.length];
for (int x = 0; x < itemsInRecord.length; x++) {
recordItem[x] = itemsInRecord[x];
Log.e(TAG, "x = " + x);
}
String withoutBraket = recordItem[0].substring(11);
String withoutSecs = withoutBraket.substring(0, 6);
Log.e(TAG, "recordItem = " + recordItem[2]);
if(recordItem[2].toString().equalsIgnoreCase("Completed")){
statusField = "c";
}else if(recordItem[2].toString().equalsIgnoreCase("NCR")){
statusField = "NCR";
}else if(recordItem[2].toString().equalsIgnoreCase("Waiting")){
statusField = "W";
}
Log.e(TAG, "statusField = " + statusField);
startTime.setText(withoutSecs );
duration.setText( recordItem[1]);
status.setText( statusField);
name.setText( recordItem[3] + recordItem[4]);
callID = recordItem[5];
needName = recordItem[6];
return rowView;
}
.
<?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="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp" >
<TextView
android:id="@+id/rowstarttime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/rowduration"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp" >
<TextView
android:id="@+id/rowstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/rowclientname"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
recordItem[2] needed trim() calling on it. .equals not picking the strings up because of this.