0
我有這個消息在我的listFragment錯誤,我已經嘗試了一些解決方案在其他議題中提出了關於同一問題,但它仍然無法正常工作。我沒有在第一時間,但片段之間的一些導航後得到的錯誤.. 以下是錯誤:ListFragment error:內容視圖尚未創建
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.rajaapp.ui.InboxFragment$2$1.done(InboxFragment.java:136)
at com.rajaapp.ui.InboxFragment$2$1.done(InboxFragment.java:121)
at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:107)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
這裏是片段代碼:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_inbox, container, false);
fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setItems(R.array.camera_choices,mDialogListener);
AlertDialog dialog = builder.create();
dialog.show();
}
});
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
mSwipeRefreshLayout.setColorSchemeResources(
R.color.swipeRefresh1,
R.color.swipeRefresh2,
R.color.swipeRefresh3,
R.color.swipeRefresh4
);
return rootView;
}
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mprogressBar = (ProgressBar) getView().findViewById(R.id.progressBar);
fab.attachToListView(getListView());
retrieveMessages();
}
private void retrieveMessages() {
mAbonnementsRelation = ParseUser.getCurrentUser().getRelation(ParseConstants.KEY_ABONNEMENTS_RELATION);
mAbonnementsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> abonnes, ParseException e) {
if(e==null){
int i = 0;
for (ParseUser abonne : abonnes) {
AbonnesIds.add(abonne.getObjectId());
i++;
}
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
query.whereContainedIn(ParseConstants.KEY_SENDER_ID, AbonnesIds);
query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
if (!mSwipeRefreshLayout.isRefreshing()) {
mprogressBar.setVisibility(View.VISIBLE);
}
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> messages, ParseException e) {
mprogressBar.setVisibility(View.INVISIBLE);
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}
if (e == null) {
mMessages = messages;
String[] usernames = new String[mMessages.size()];
int i = 0;
for (ParseObject message : mMessages) {
usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
i++;
}
if (getListView().getAdapter() == null) {
MessageAdapter adapter = new MessageAdapter(getListView().getContext()
, mMessages);
setListAdapter(adapter);
} else {
((MessageAdapter) getListView().getAdapter()).refill(mMessages);
((MessageAdapter) getListView().getAdapter()).notifyDataSetChanged();
}
}
}
});
}
else{
Log.e(TAG,e.getMessage());
}
}
});
}
中出現的錯誤這條線:
if (getListView().getAdapter() == null) {
仍然具有相同的錯誤在if(getListView()。getAdapter()== null):/ – Anas
使用列表活動 –
我不能,我使用fragmentPagerAdapter,有一個3其他碎片其實 – Anas