特定の条件がtrueであることに基づいて、リストビューで特定の行をハイライトしたいと思います。次のコードを試して、NULLポインタ例外が発生しました。特定の条件がtrueの場合、リストビューの行の色を変更しますか?
public class BillsCustomList extends ArrayAdapter<String>
{
private String[] doc_no;
private String[]date;
private String[] cust_name;
private String[] cust_number;
private String[] item_count;
private String[]total_wt;
private String[]total;
private String[]balance;
private String[]bill_type;
private String[]status;
private Activity context;
public BillsCustomList(Activity context, String[] doc_no, String[] date, String[] cust_name,String[] cust_number,
String[] item_count,String[] total_wt,String[] total,String[] balance,String[] bill_type,String[] status)
{
super(context, R.layout.bills_list_view, doc_no);
this.context =context;
this.doc_no=doc_no;
this.date = date;
this.cust_name = cust_name;
this.cust_number = cust_number;
this.item_count= item_count;
this.total_wt = total_wt;
this.total = total;
this.balance = balance;
this.bill_type = bill_type;
this.status = status;
}
@Override
public View getView(int position, View listViewItem, ViewGroup parent)
{
if (null == listViewItem) {
LayoutInflater inflater = context.getLayoutInflater();
listViewItem = inflater.inflate(R.layout.bills_list_view, null, true);
}
TextView textViewDocno = (TextView) listViewItem.findViewById(R.id.textViewInvNo);
TextView textViewDt = (TextView) listViewItem.findViewById(R.id.textViewDt);
TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName);
TextView textViewNumber = (TextView) listViewItem.findViewById(R.id.textViewNumber);
TextView textViewCount = (TextView) listViewItem.findViewById(R.id.textViewCount);
TextView textViewTotwt = (TextView) listViewItem.findViewById(R.id.textViewTotwt);
TextView textViewTot = (TextView) listViewItem.findViewById(R.id.textViewTot);
TextView textViewBal = (TextView) listViewItem.findViewById(R.id.textViewBalanace);
TextView textViewBt = (TextView) listViewItem.findViewById(R.id.textViewBt);
TextView textViewStatus = (TextView) listViewItem.findViewById(R.id.textView_status);
LinearLayout ll = (LinearLayout) listViewItem.findViewById(R.id.ll_bills);
textViewDocno.setText(doc_no[position]);
textViewDt.setText(date[position]);
textViewName.setText(cust_name[position]);
textViewNumber.setText(cust_number[position]);
textViewCount.setText(item_count[position]);
textViewTotwt.setText(total_wt[position]);
textViewTot.setText(total[position]);
textViewBal.setText(balance[position]);
textViewBt.setText(bill_type[position]);
textViewStatus.setText(status[position]);
try
{
if (textViewStatus.getText().toString().equalsIgnoreCase("true"))
{
ll.setBackgroundColor(Color.RED);
}
}catch (NullPointerException e)
{
Log.d("NULL ERROR", "position"+position+e);
}
return listViewItem;
}
}
I have simple use case if the status is true make the row of a certain color.Else don't do anything.I get the following error when I try the above code.
NULL ERROR: position0java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference
私はこの出来事とそれを行うための正しい方法だろうが、なぜ0と1 position.Can誰でこれらのnullポインタ例外が説明し得ます。 何か助けや助言を歓迎します。ありがとうございます。
if (position < status.length() && status[position].equalsIgnoreCase("true"))
ll.setBackgroundColor(Color.RED);
else
ll.setBackgroundResource(android.R.color.transparent);
私はすべての希望:
は、 'equalsIgnoreCase'の代わりに' equals'を使用して、やり直してください。 –
@vrundpurohit私は等しくしようとしましたが、何の違いもありませんでした。 – AndroidNewBee
if(status [position] .compareTo( "true")== 0) { listViewItem.setBackgroundColor()... } – Nanoc