I have a ListView and a SimpleCursorAdapter. I add two rows (each is a reminder): the first has a title, date and countdown string, the second has a title and an address (location).
For some reason, the ViewHolder's mCountDownString from row #2 has the value from row #1.
Doesn't it create a ViewHolder object for each row? If yes, why isn't mCountDownString empty for the address reminder row?
private static class ViewHolder {
TextView mTitle;
TextView mDate;
String mDateString;
TextView mCountDown = null;
String mCountDownString;
TextView mAddress;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
mCursor = (Cursor) getItem(position);
if(convertView == null)
{
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.row, parent, false);
holder.mTitle = (TextView) convertView.findViewById(R.id.titleID);
//holder.mAddress = (TextView) convertView.findViewById(R.id.dateTimeOrLocationID);
//holder.mDate = (TextView) convertView.findViewById(R.id.dateTimeOrLocationID);
// edit: changed to use a separate view
holder.mAddress = (TextView) convertView.findViewById(R.id.addressId);
holder.mDate = (TextView) convertView.findViewById(R.id.dateTimeId);
holder.mCountDown = (TextView) convertView.findViewById(R.id.countdownID);
holder.mCountDownString = null;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
int colorPos = mCursor.getPosition() % colors.length;
convertView.setBackgroundColor(colors[colorPos]);
int col = mCursor.getColumnIndex(ReminderColumns.TITLE);
holder.mTitle.setText(mCursor.getString(col));
col = mCursor.getColumnIndex(ReminderColumns.ADDRESS);
String address = mCursor.getString(col);
if(address != null)
{
// No. 1: it's an address: set only title + address fields
System.out.println("title for address: " + holder.mTitle.getText());
holder.mAddress.setText(address);
holder.mDate.setText(""); // edit
holder.mCountDown.setText("");
holder.mCountDownString = "";
}
else
{
// No. 2: it's date: set only title + date + countDownString fields
col = mCursor.getColumnIndex(ReminderColumns.DATE);
Date date = new Date(mCursor.getLong(col));
SimpleDateFormat timeFormat2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm");
String dateStr = timeFormat2.format(date);
holder.mDate.setText(dateStr);
String countDownStr = getTimeDiff(date);
holder.mCountDown.setText(countDownStr);
holder.mCountDownString = countDownStr;
holder.mAddress.setText(""); // edit
}
return convertView;
}
EDIT
I clear all holder's member variables if they're not used. But the problem still persists: for a date row, it doesn't display holder.mDate and for a address row, it doesn't show holder.mAddress. Something is mixed up.
When I create the adapter, the cursor is initially null. That's why I'm setting it in getView().
Edit 2
I changed my code so I'm not using dateTimeOrLocationID for holder.mAddress and holder.mDate. The problem now is, that there's an empty view which takes up space. F.e. if I add a date and leave R.id.addressId empty, the empty space is still visible. Is there a way to avoid that? And would you mind explaning why my first approach didn't work?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="false"
android:clickable="false"
android:descendantFocusability="afterDescendants">
<TextView
android:id="#+id/titleID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:focusable="false"
android:clickable="false"
android:textColor="#color/black" />
<TextView
android:id="#+id/dateTimeId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:focusable="false"
android:clickable="false"
android:textColor="#color/black" />
<TextView
android:id="#+id/addressId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:focusable="false"
android:clickable="false"
android:textColor="#color/black" />
<TextView
android:id="#+id/countdownID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:focusable="false"
android:clickable="false"
android:textColor="#color/black" />
</LinearLayout>
No it doesn't create a viewholder for each row in your list. You got 1 viewholder for each convertview which is about as many rows that can be shown at the screen simoultanously. You need to update the content each time getView is called.
Edit:
Your mDate and mAddress use the same view. Search for: R.id.dateTimeOrLocationID abd it becommes clear to you :)
Related
I am using an custom adapter and I have the problem with getView method. Here is my code -
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (vi == null)
vi = inflater.inflate(R.layout.list_item, null);
if(position==0){
TextView text1 = (TextView) vi.findViewById(R.id.text1);
text1.setText(data[position]);
}else if(position==1){
TextView text2 = (TextView) vi.findViewById(R.id.text2);
text2.setText(data[position]);
}
return vi;
}
and here is the XML file -
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#android:color/black"
android:textColor="#android:color/white"
android:id="#+id/text1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#android:color/green"
android:textColor="#android:color/white"
android:id="#+id/text2" />
</LinearLayout>
Actually my if command is working but the other blank textView also appears with it.
Suppose If position==0 then "#+id/text1" should be displayed, but "#+id/text2" also get displayed with no text.
I want only one textview to be displayed, not the other one. How to do that?
position is the index of the currently displayed item in the adapter, not which TextView is being displayed.
Each row of your Adapter has two TextViews, and I assume you have some string that needs to be displayed in both views.
As an example, try this instead.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
String item = String.valueOf(data[position]);
View v = convertView;
if (v == null) {
v = inflater.inflate(R.layout.list_item, null);
}
TextView text1 = (TextView) v.findViewById(R.id.text1);
TextView text2 = (TextView) v.findViewById(R.id.text2);
text1.setText("1: " + item);
text2.setText("2: " + item);
return v;
}
I want only one textview to be displayed, not the other one. How to do that?
Then it sounds like you don't want two TextViews in one layout...
If you question is literally "How to display more than one TextView in a ListView", then you should put more than one value into that data array.
when writing an app for me and my roommates to calculate our food-payments I got stuck on such problem:
when adding new payment, you:
1) select name from RadioGroup
2) give value
3) give description (or leave default 'opis')
then after pressing button "DODAJ" it shows as new item in ListView with certain format. Now the problem begins:
I want to make it so when I click on a Item in this list, i will slightly change format of this certain item (in NowaWplata class I got extra time to be displayed) which I got in another .xml layout file, and when pressing it again it should go back to 'normal' layout.
I tried 2 different approaches, one is commented in the bottom of my code (I tried it from this topic Change layout of selected list item in Android), and the other one is in overriden onItemClick method - neither of them worked
compiler says that the error is :
java.lang.NullPointerException
at com.example.lukasz.dom.MainActivity.onItemClick
in this line of code:
relativeLayoutInflate.addView(child);
in main activity (onClick only for 'lukasz', same for 'marcelina' and 'karolina'):
#Override
public void onClick(View v) {
if (v == addNewPaymentButton) {
//checking which button from RadioGroup is checked and adding new payment to certain person
int checkedRadioButtonId = members.getCheckedRadioButtonId();
switch (checkedRadioButtonId) {
//if Lukasz button is pressed, do:
case R.id.lukaszRadioButton:
if (lukaszRadioButton.isChecked()) {
//add value from addNewPaymentButton to tempLukasz
try {
tempLukasz += valueOf(newPaymentValue.getText().toString());
} catch (NumberFormatException e) {
}
//seting new value to money spent by lukasz
String sumaLukasza = getString(R.string.money_spent_by_lukasz);
sumaLukasza = String.format(sumaLukasza, tempLukasz);
moneySpentByLukasz.setText(sumaLukasza);
//adding new payment to list of all payments with flag 'int == 1' to set color to RED
NowaWplata newPayment = new NowaWplata(lukaszRadioButton.getText().toString(), newPaymentValue.getText().toString(), descriptionOfNewPayment.getText().toString(), 1);
NowaWplata.setWplaty(newPayment);
listView.setAdapter(new NewPaymentAdapter(this, R.layout.new_list_item_layout, NowaWplata.getWplaty()));
}
break;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView hourDate = (TextView) view.findViewById(R.id.hoursDateFieldInSelectedListItem);
TextView dayDate = (TextView) view.findViewById(R.id.daysDateFieldInSelectedListItem);
TextView name = (TextView) view.findViewById(R.id.nameFieldInSelectedListItem);
TextView value = (TextView) view.findViewById(R.id.valueFieldInSelectedListItem);
TextView description = (TextView) view.findViewById(R.id.descriptionFieldInSelectedListItem);
RelativeLayout relativeLayoutInflate = (RelativeLayout) view.findViewById(R.id.layoutOfSelectedListItem);
NowaWplata newPayment = (NowaWplata) listView.getItemAtPosition(position);
View child = getLayoutInflater().inflate(R.layout.selected_list_item, null);
relativeLayoutInflate.addView(child);
hourDate.setText("[" + newPayment.getHourDate() + "]");
dayDate.setText(newPayment.getDayDate());
name.setText(newPayment.getOsoba());
value.setText(newPayment.getWplata() + "zł");
description.setText(newPayment.getOpis());
}
}
//custom adapter class
class NewPaymentAdapter extends ArrayAdapter<NowaWplata> {
public LayoutInflater layoutInflater;
//custom adapter's constructor with values
public NewPaymentAdapter(Context context, int textViewResourceId, List<NowaWplata> wplaty) {
super(context, textViewResourceId, wplaty);
layoutInflater = LayoutInflater.from(context);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
NowaWplata newPayment = getItem(position);
Holder holder = null;
// private int position;
// public void selectedItem(int position)
// {
// this.position = position;
// }
//if there are no items in list - add 1st item
if (view == null) {
view = layoutInflater.inflate(R.layout.new_list_item_layout, null);
TextView name = (TextView) view.findViewById(R.id.osobaWplata);
TextView value = (TextView) view.findViewById(R.id.kwotaWplata);
TextView description = (TextView) view.findViewById(R.id.opisWplata);
holder = new Holder(name, value, description);
view.setTag(holder);
}
// if there are items in list get holder tag
else {
holder = (Holder) view.getTag();
}
//setting text to a new list item
holder.osoba.setText("[" + newPayment.getDate() + "] " + newPayment.getOsoba());
holder.kwota.setText(newPayment.getWplata() + "zł");
holder.opis.setText(newPayment.getOpis());
//setting different color to Lukasz/Marcelina/Karolina text
if (newPayment.getFlag() == 1) {
holder.osoba.setTextColor(Color.RED);
} else if (newPayment.getFlag() == 2) {
holder.osoba.setTextColor(Color.BLUE);
} else if (newPayment.getFlag() == 3) {
holder.osoba.setTextColor(Color.GREEN);
}
//setting color to payment's value
holder.kwota.setTextColor(Color.BLACK);
// if (this.position == position) {
// View view2;
// view2 = layoutInflater.inflate(R.layout.selected_list_item, null);
//
// TextView hourDate = (TextView) view2.findViewById(R.id.hoursDateFieldInSelectedListItem);
// TextView dayDate = (TextView) view2.findViewById(R.id.daysDateFieldInSelectedListItem);
// TextView name = (TextView) view2.findViewById(R.id.nameFieldInSelectedListItem);
// TextView value = (TextView) view2.findViewById(R.id.valueFieldInSelectedListItem);
// TextView description = (TextView) view2.findViewById(R.id.descriptionFieldInSelectedListItem);
//
// hourDate.setText("[" + newPayment.getHourDate() + "]");
// dayDate.setText(newPayment.getDayDate());
// name.setText(newPayment.getOsoba());
// value.setText(newPayment.getWplata() + "zł");
// description.setText(newPayment.getOpis());
//
// return view2;
// }
return view;
}
}
this is the main XML part with the ListView
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#android:id/list"
android:layout_below="#+id/tableLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/newPaymentValue"
android:layout_alignRight="#+id/tableLayout"
android:layout_alignEnd="#+id/tableLayout"
android:choiceMode="none"
android:clickable="false"
android:padding="20dp"
android:transcriptMode="disabled"/>
this is the xml of a new item in list
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layoutOfSelectedListItem">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/hoursDateFieldInSelectedListItem"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="18dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/daysDateFieldInSelectedListItem"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="18dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/nameFieldInSelectedListItem"
android:layout_below="#+id/hoursDateFieldInSelectedListItem"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/daysDateFieldInSelectedListItem"
android:layout_toStartOf="#+id/daysDateFieldInSelectedListItem"
android:textSize="18dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/valueFieldInSelectedListItem"
android:layout_below="#+id/daysDateFieldInSelectedListItem"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/descriptionFieldInSelectedListItem"
android:layout_below="#+id/nameFieldInSelectedListItem"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textSize="14dp" />
I have done that by adding extra layout.
ListItem:
<--Your listItem view--!>
<RelativeLayout>
<--Your extra View--!>
<LinearLayout
android:tag="0"
android:visibility="gone">
</LinearLayout>
</RelativeLayout>
In your OnItemClickListener set the extra layout to visible and also set the tag accordingly to save the state of the extra view.
Here is my code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View rowView = convertView;
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
PlannerMonth m = getItem(position);
ArrayList<PlannerMonthDebt> debts = new ArrayList<PlannerMonthDebt>();
debts = m.debtList;
int debtSize = debts.size();
if (rowView == null) {
rowView = inflater.inflate(R.layout.row_planner_month, null, true);
holder = new ViewHolder();
holder.tv1 = (TextView) rowView.findViewById(R.id.tvPlannerMonth);
holder.tv2 = (TextView)
holder.ll = (LinearLayout) rowView.findViewById(R.id.rlInnerDebtHolder);
for (int i = 0; i < debtSize; i++) {
View custom = inflater.inflate(R.layout.inner_debt_row, null);
TextView tvName = (TextView) custom.findViewById(R.id.tvInnerDebtName);
tvName.setTag(String.valueOf("tvName" + i));
TextView tvPayment = (TextView) custom.findViewById(R.id.tvInnerDebtPayment);
tvPayment.setTag(String.valueOf("tvPayment" + i));
TextView tvDebt = (TextView) custom.findViewById(R.id.tvInnerDebtBalance);
tvDebt.setTag(String.valueOf("tvDebt" + i));
TextView tvBalance = (TextView) custom.findViewById(R.id.tvInnerDebtFee);
tvBalance.setTag(String.valueOf("tvBalance" + i));
holder.ll.addView(custom);
}
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
String month = m.date;
String debtToal = m.debtTotal;
String intTotal = m.intTotal;
holder.tv1.setText(month);
holder.tv2.setText(debtToal);
// now inner debts
int size = 0;
for (PlannerMonthDebt d : debts) {
TextView tvName = (TextView) convertView.findViewWithTag(String.valueOf("tvName" + size));
tvName.setText(d.name);
TextView tvPayment = (TextView) convertView.findViewWithTag(String.valueOf("tvPayment" + size));
tvPayment.setText(d.payment);
TextView tvDebt = (TextView) convertView.findViewWithTag(String.valueOf("tvDebt" + size));
tvDebt.setText(d.balance);
TextView tvBalance = (TextView) convertView.findViewWithTag(String.valueOf("tvBalance" + size));
tvBalance.setText(d.fees);
size++;
}
return rowView;
}
Here is the row I am trying to dynamically add:
inner_debt_row.xml:
<?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="horizontal" >
<TextView
android:id="#+id/tvInnerDebtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/tvInnerDebtFee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/tvInnerDebtPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="TextView" />
<TextView
android:id="#+id/tvInnerDebtBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
I have a LinearLayout (holder.ll) where I add an X number of custom rows (based on the inner_debt_row layout pasted above).
I know how to show the rows, but I am having trouble using setTag() to find and retrieve them so I can put values to them (via setText().
For the tag, I basically use a same name for each TextView, but ALSO add a unique position to the name. I use the position (or size) to keep each of the dynamically added text fields unique for searching.
In my LogCat, I get a NullPointer on this line:
TextView tvName = (TextView) convertView.findViewWithTag(String.valueOf("tvName" + size));
This is the first encounter with assigning a value to a dynamic TextView so I assume they all can not be found.
How can I locate the correct TextView instance whit by tag?
The findViewWithTag() code looks correct. Did you check that convertView isn't null?
convertView will be null when creating a new row (i.e. not reusing a previous one), but you are assigning rowView only, and not convertView.
You have different debtSize in each position. When convertView != null and have less debtSize you have NullPointer's, when more - you have empty textviews.
Im new to android and Im building an app to show stock prices from an XML feed.
I have got an array list containing 3 items. However, I want to change the color of one of the items in the array list to red if its -ve or green if its +ve.
I dont know how to do this or where in my code is best to do it.
Please help....
My Adapter class:
public class TheAdapter extends ArrayAdapter<TheMetal>{
public TheAdapter(Context ctx, int textViewResourceId, List<TheMetal> sites) {
super(ctx, textViewResourceId, sites);
}
#Override
public View getView(int pos, View convertView, ViewGroup parent){
RelativeLayout row = (RelativeLayout)convertView;
Log.i("StackSites", "getView pos = " + pos);
if(null == row){
LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = (RelativeLayout)inflater.inflate(R.layout.row_metal, null);
}
TextView dispNameTxt = (TextView)row.findViewById(R.id.displayNameText);
TextView spotPriceTxt = (TextView)row.findViewById(R.id.spotPriceText);
TextView changeTxt = (TextView)row.findViewById(R.id.changeText);
dispNameTxt.setText (getItem(pos).getDisplayName());
spotPriceTxt.setText(getItem(pos).getSpotPrice());
changeTxt.setText(getItem(pos).getChange());
return row;
}
My row_metal layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp" >
<TextView
android:id="#+id/displayNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_marginLeft="20dp" />
<TextView
android:id="#+id/spotPriceText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/displayNameText"
android:textSize="19sp"
android:textStyle="bold"
android:gravity="right"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp" />
<TextView
android:id="#+id/changeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spotPriceText"
android:layout_toRightOf="#+id/displayNameText"
android:textSize="16sp"
android:gravity="right"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
/>
It is so simple. You just need to place these line within your getView() method:
if (Double.parseDouble(getItem(pos).getChange())>=0) {
row.setBackgroundColor(Color.parseColor("#00FF00");
changeTxt.setTextColor(Color.parseColor("#00FF00"));
} else {
row.setBackgroundColor(Color.parseColor("#FF0000");
changeTxt.setTextColor(Color.parseColor("#FF0000"));
}
Change your getView() method to this
#Override
public View getView(int pos, View convertView, ViewGroup parent){
if(convertView == null)
convertView = getLayoutInflater().inflate(R.layout.row_metal, null);
TextView dispNameTxt = (TextView) convertView .findViewById(R.id.displayNameText);
TextView spotPriceTxt = (TextView) convertView .findViewById(R.id.spotPriceText);
TextView changeTxt = (TextView) convertView .findViewById(R.id.changeText);
dispNameTxt.setText(getItem(pos).getDisplayName());
spotPriceTxt.setText(getItem(pos).getSpotPrice());
changeTxt.setText(getItem(pos).getChange());
if( Double.parseDouble(getItem(pos).getSpotPrice()) >= 0 )
convertView.setBackgroundColor(Color.GREEN);
else
convertView.setBackgroundColor(Color.RED);
return convertView;
}
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.