ListView의 모든 요소를 검사하여 해당 레이블 중 하나만 레이블을 설정해야합니다. 데이터베이스 또는 어댑터를 편집 할 수 없습니다. ListView를 스크롤하여 TextView에 문자열을 설정하고 검사를 수행하기 만하면됩니다.getChildCount()는 ListView에서 0을 반환합니다.
@Override
protected void onResume(){
super.onResume();
...
cursor = getCursor();
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this,R.layout.profile_item_layout,cursor,from,to);
lst_profiles.setAdapter(adapter);
SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(ProfilerActivity.this.getApplicationContext());
long current = customSharedPreference.getLong(ProfileManager.CURRENT, -1);
toast(lst_profiles.getChildCount()); //display 0
if(current!=-1){
for(int i=0;i<lst_profiles.getChildCount();i++){
if(lst_profiles.getItemIdAtPosition(i)==current)
((TextView)lst_profiles.getChildAt(i).findViewById(R.id.activeLabel)).setText(getString(R.string.active));
else
((TextView)lst_profiles.getChildAt(i).findViewById(R.id.activeLabel)).setText("");
}
}
}
어떻게하면됩니까? 기다릴 필요가 있니?
P. 대개 ListView는 비어 있지 않습니다.
당신이() 여기 getCursor를 호출하는 방법? 이것에 대한 Activity 또는 Context 메서드가 보이지 않습니다 ... – Maximus
예 onResume() 내부에서 getCursor()를 호출합니다. 응용 프로그램이 잘 작동, 유일한 문제는 0 getChildCount()입니다 – JoP