다른보기 아래에 표시되도록 설정된보기가 3 개 있습니다. 그러나 문제는이보기 (가운데 하나)가 화면에 전혀 나타나지 않는다는 것입니다. 이 목록을 상위보기로 보내는 방법에 대해서는 확실하지 않습니다. 여기 http://tausiq.wordpress.com/2012/12/12/android-custom-adapter-listview-with-listfragment-and-loadermanager-inside-fragmentactivity/Android : 중간 조각이 표시되지 않습니다.
코드입니다 : 여기
public class MyActivity extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.my_activity_layout, container, false);
DataListFragment list = new DataListFragment();
return view;
}
public static class DataListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<List<Model>> {
CustomListViewAdapter mAdapter;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setEmptyText("No Data Here");
mAdapter = new CustomListViewAdapter(getActivity());
setListAdapter(mAdapter);
setListShown(false);
// Prepare the loader.
getLoaderManager().initLoader(0, null, this);
}
@Override
public Loader<List<Model>> onCreateLoader(int arg0, Bundle arg1) {
System.out.println("DataListFragment.onCreateLoader");
return new DataListLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<List<Model>> arg0, List<Model> data) {
mAdapter.setData(data);
System.out.println("DataListFragment.onLoadFinished");
// The list should now be shown.
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
@Override
public void onLoaderReset(Loader<List<Model>> arg0) {
mAdapter.setData(null);
}
}
public static class DataListLoader extends AsyncTaskLoader<List<Model>> {
List<Model> mModels;
public DataListLoader(Context context) {
super(context);
}
@Override
public List<Model> loadInBackground() {
System.out.println("DataListLoader.loadInBackground");
List<Model> entries = new ArrayList<Model>(5);
entries.add(new Model("1", "2","3"));
entries.add(new Model("1", "2","3"));
entries.add(new Model("1", "2","3"));
return entries;
}
/**
* Called when there is new data to deliver to the client.
*/
@Override public void deliverResult(List<Model> listOfData) {
if (isReset()) {
// An async query came in while the loader is stopped. We
// don't need the result.
if (listOfData != null) {
onReleaseResources(listOfData);
}
}
List<Model> oldApps = listOfData;
mModels = listOfData;
if (isStarted()) {
// If the Loader is currently started, we can immediately
// deliver its results.
super.deliverResult(listOfData);
}
// At this point we can release the resources associated with
// 'oldApps' if needed; now that the new result is delivered we
// know that it is no longer in use.
if (oldApps != null) {
onReleaseResources(oldApps);
}
}
/**
* Handles a request to start the Loader.
*/
@Override protected void onStartLoading() {
if (mModels != null) {
// If we currently have a result available, deliver it
// immediately.
deliverResult(mModels);
}
if (takeContentChanged() || mModels == null) {
// If the data has changed since the last time it was loaded
// or is not currently available, start a load.
forceLoad();
}
}
/**
* Handles a request to stop the Loader.
*/
@Override protected void onStopLoading() {
// Attempt to cancel the current load task if possible.
cancelLoad();
}
/**
* Handles a request to cancel a load.
*/
@Override public void onCanceled(List<Model> apps) {
super.onCanceled(apps);
// At this point we can release the resources associated with 'apps'
// if needed.
onReleaseResources(apps);
}
/**
* Handles a request to completely reset the Loader.
*/
@Override protected void onReset() {
super.onReset();
// Ensure the loader is stopped
onStopLoading();
// At this point we can release the resources associated with 'apps'
// if needed.
if (mModels != null) {
onReleaseResources(mModels);
mModels = null;
}
}
/**
* Helper function to take care of releasing resources associated
* with an actively loaded data set.
*/
protected void onReleaseResources(List<Model> apps) {}
}
}
사용자 정의 어댑터입니다 :
이것은 내가 사용하고 튜토리얼입니다
public class CustomListViewAdapter extends ArrayAdapter<Model>{
private final LayoutInflater mInflater;
public CustomListViewAdapter(Context context) {
super(context, android.R.layout.simple_list_item_2);
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setData(List<Model> data) {
clear();
if (data != null) {
for (Model appEntry : data) {
add(appEntry);
}
}
}
/**
* Populate new items in the list.
*/
@Override public View getView(int position, View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
view = mInflater.inflate(R.layout.single_item, parent, false);
} else {
view = convertView;
}
Model item = getItem(position);
((TextView)view.findViewById(R.id.tV_1)).setText(item.getA());
((TextView)view.findViewById(R.id.tV_2)).setText(item.getB());
((TextView)view.findViewById(R.id.tV_3)).setText(item.getC());
return view;
}
}
그리고 이것은 내 주요 활동 :
public class MainActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.song_info_fragment, new TopActivity());
fragmentTransaction.add(R.id.playlist_activity_fragment, new MyActivity());
fragmentTransaction.add(R.id.controls_fragment, new BottomActivity());
fragmentTransaction.commit();
}
}
코드를 실행할 때 위쪽 및 아래쪽 작업 만 표시됩니다. 이 문제를 어떻게 해결할 수 있습니까?
다른 클래스 내에 Fragment 클래스가 있습니다. – Raghunandan
@Raghunandan, 고마워, 나는 그것이 허용되지 않았다는 것을 몰랐다. 사용할 수있는 수정 사항을 알려주십시오. – Codename