我正在使用简单游标适配器来填充sherlockListFragment中的列表。我已经使用加载器完成了此操作。但是当我尝试为列表中的文本添加颜色时。我得到 Java.lang.Null.pointer异常。而我的java代码是
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Log.i("live", "onActivityCreated");
super.onActivityCreated(savedInstanceState);
setEmptyText("Loading...");
SimpleCursorAdapter.ViewBinder vb=new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View arg0, Cursor arg1, int arg2) {
Log.i("alls","inside set View Value");
View inflate=getActivity().getLayoutInflater().inflate(R.layout.live_list_stock,null);
TextView tv=(TextView)inflate.findViewById(R.id.lpercent);
tv.setTextColor(Color.RED);
//String i=tv.getText().toString();
//Log.i("alls",(i));
// TODO Auto-generated method stub
return true;
}
};
liveMyStocksadapter = new SimpleCursorAdapter(getActivity().getApplicationContext(), R.layout.live_list_item, null, new String[] {DBConstants.NAME,DBConstants.YSYMBOL,DBConstants.PRICE,DBConstants.PERCENT,DBConstants.DATE,DBConstants.TIME,DBConstants.OPEN,DBConstants.HIGH,DBConstants.LOW,DBConstants.VOLUME}, new int[] {R.id.lname,R.id.lysymbol, R.id.lprice,R.id.lpercent,R.id.ldate,R.id.ltime,R.id.lopen,R.id.lhigh,R.id.llow,R.id.lvolume},0);
setListAdapter(liveMyStocksadapter);
mycontext=this;
getActivity().registerReceiver(FragmentReceiver1, new IntentFilter("fragmentupdater"));
getActivity().getSupportLoaderManager().initLoader(0, null, this);
liveMyStocksadapter.setViewBinder(vb);
谢谢你的帮助..