에 매번로드되는 것을 방지 Android에서 이 대화 상자는 단편 내부에만있는 목록보기에서 팝업됩니다.데이터가 내가 SQLite 데이터베이스에서로드되고 난 대화 상자 안에 목록보기와 목록보기의 내용이 내 사용자 지정 대화 상자에서 <code>Android Compatibility Support Package</code></p> <p>의 도움으로 사용자 정의 AlergDialog 사용 DialogFragment를 만든 DialogFragment
이제 t, listview (어느 조각 안에 있음)를 클릭 할 때마다 대화 상자에 데이터가 listview에 성공적으로 표시되지만 매번 listitem (조각 안에 있음)을 누를 때마다 데이터가로드됩니다 onCreate is being called every time
bcoz 대화 상자의 목록보기에서 데이터베이스에서 그렇게 내가 원하는 WHT 조각에서을 listitem 클릭됩니다 때마다 data should be loaded at once for all listitem of listview which is inside of fragment.
코드
, 나는 사용자 정의 DialogFragment에 전화를 걸입니다
DalogFragment newFragment = TemplateToContact.newInstance("hi");
newFragment.show(getFragmentManager(), "dialog");
,
에서 OnCreate이 onCreateDialog에서
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
contactDB = new ContactDB(getActivity().getApplicationContext());
contactDataList = contactDB.getAllContacts();
templateContactAdapter = new TemplateContactAdapter();
}
DialogFragment
의 i는 사용자 정의에 AlertDialog 상자를 만들 adapger를 설정하고@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater factory = LayoutInflater.from(getActivity());
View v = factory.inflate(R.layout.cdialog, null);
builder = new AlertDialog.Builder(getActivity());
builder.setView(v);
templateContactDlg = builder.create();
templateContactList = (ListView)v.findViewById(R.id.contactDlgList);
templateContactList.setAdapter(templateContactAdapter);
return templateContactDlg;
}
DialogFragment 클래스를 확장하고 클래스 내에서 onCreateDialog menthod를 재정의하고 AlertDialog 상자를 마스킹하고 반환하면 AlertDialog 섹션을 가로 지르는 동일한 링크를 볼 수 있습니다. – Hunt
Do 당신은 onStop과 onCreate 사이에 데이터를 저장하기 위해 savedInstanceState를 사용합니까? 나는 대개 내 조각과 dao 사이에 데이터 관리자 클래스가 있습니다. 관리자 클래스는 @Injected이며 데이터를 캐시합니다. – Christine
사용 방법을 모르겠다. 샘플 코드 스 니펫 코드 – Hunt