我想在活动创建时将 SpannableString 设置为 ListView 的某些项目。
我这样写:
doListlist=(ListView)findViewById(R.id.dolist_List);
listsDbAdapter=new yueDataBaseAdapter(this);
listsDbAdapter.open();
UpdataAdpter();
for(int i = 0; i < doListlist.getChildCount(); i++) {
if (listsDbAdapter.fetchData(tableName, i+1).getString(7).length() == 4) {
View view = doListlist.getChildAt(i);
String drawText=listsDbAdapter.fetchData(tableName,i+1).getString(1);
TextView txtInfo =(TextView)view.findViewById(R.id.doList_itemname);
SpannableString ss = new SpannableString(drawText);
ss.setSpan(new StrikethroughSpan(), 0, drawText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
txtInfo.setText(ss);
}
}
public void UpdataAdpter(){
Cursor cur= listsDbAdapter.fetchAllData(tableName);
if(cur!=null&& cur.getCount()>=0){
adapter =new SimpleCursorAdapter(this,
R.layout.dolist_item,
cur,
new String[]{yueDataBaseAdapter.KEY_NAME,yueDataBaseAdapter.KEY_PRICESTR,yueDataBaseAdapter.KEY_NUMSTR},
new int[]{R.id.doList_itemname,R.id.doList_itemPrice,R.id.doList_itemNum}
);
doListlist.setAdapter(adapter);
}
}
但我发现 doListlist.getChildCount() 总是 = 0。
问题出在哪里?或者任何其他更好的方法来做到这一点?