활동을 만들 때 ListView의 일부 항목에 SpannableString을 설정해야합니다.왜 ListView.getChildCount() == 0 (항상)입니까?
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
이 문제는 어디 것을 알게 :
나는 이렇게 쓰기? 아니면 이것을하는 다른 더 좋은 방법이 있을까요?
목록에 제대로 채워지지 않습니다. 사용중인 코드를 표시하십시오. – Aidanc
doListList.getAdapter(). getCount()를 사용해보십시오. – blessenm