SimpleCursorAdapter를 사용하는 대신 확장하십시오. 그런 다음 getView에서 UI (텍스트 색상, 글꼴 크기 등)를 변경할 수 있습니다. 어댑터 또는 환경 (onCreate ...)에서 환경 설정 관리자를 통해 환경 설정을 조회하여 설정 활동에서 설정된 색상이나 크기를 얻을 수 있습니다.
활동 사이에서 통신하기 위해 처리기를 사용할 수 없습니다.
업데이트, 명확성이 부족해서 죄송합니다. ListActivity가 아닌 어댑터를 재정의해야합니다. 활동에
:
private void populateContactList() {
Cursor cursor = getContacts();
fields = new String[] { ContactsContract.CommonDataKinds.Email.DATA };
adapter = new MyAdapter(this, R.layout.entry, cursor, fields,
new int[] { R.id.contactEntryText });
mContactList.setAdapter(adapter);
}
MyAdapter 간단한 커서 어댑터를 확장 사용자 정의 어댑터입니다 여기에 몇 가지 코드입니다. 필요한 경우 각 행에서 텍스트보기를 찾고 일부 속성을 변경 (내 이해)했으면 super.getView를 호출하여 각 행의 ViewGroup을 가져온 다음 해당 ViewGroup의 findViewById를 호출하여 TextView를 가져올 수 있습니다. 일단 그렇게하면 원하는대로 속성을 변경할 수 있습니다. 다음은 가장 기본적인 구현 개요입니다.
private static class MyAdapter extends SimpleCursorAdapter{
public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
//you could use context to get PreferenceManager and find the
//colors/sizes set in your settings activity here
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup rowView = (ViewGroup) super.getView(position, convertView, parent);
final TextView yourText = (TextView) rowView.findViewById(R.id.yourTextViewId);
yourText.setTextColor(...);
yourText.setTextSize(...);
}
}