Home > Mobile >  From the Activity returns to the ListView can't display fragments
From the Activity returns to the ListView can't display fragments

Time:09-25

Fragments of code is as follows:
 

Public class TodolistFragment extends fragments {

Private List Todos=new ArrayList<> (a);
//the NotificationManager NotificationManager.
SimpleAdapter adapter.
ListView ListView.
View the View;
The Button Button;
Private int uid;
Private String for the date.
@ Override
Public void onAttach (Context Context) {
Super. OnAttach (context);
Uid=((HomePage) context.) user_id,
The date=((HomePage) context). The date;
//buttonClickListener=(OnItemButtonClickListener) context;
}

@ Override
Public void onActivityCreated (Bundle savedInstanceState) {
Super. OnActivityCreated (savedInstanceState);
The button=(button) getActivity (). The findViewById (da dd_list R.i);
Button. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
ShowDialog ();
}
});
LocalBroadcastManager broadcastManager=LocalBroadcastManager. GetInstance (getActivity ());
IntentFilter IntentFilter=new IntentFilter ();
IntentFilter. AddAction (" android. Intent. Action. CART_BROADCAST ");
BroadcastReceiver mItemViewListClickReceiver=new BroadcastReceiver () {
@ Override
Public void onReceive (Context Context, Intent Intent) {
String MSG=intent. GetStringExtra (" data ");
If (" refresh ". The equals (MSG))
The init ();
}
};
BroadcastManager. RegisterReceiver (mItemViewListClickReceiver intentFilter);
}

@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View=inflater. Inflate (R.l ayout. Activity_todolist_fragment, container, false);
The init ();
ListView=(listView) view. The findViewById (R.i d.l ist);
Return the view;
}
/* public interface OnItemButtonClickListener {
Void onItemViewClick (View v);
} */

@ Override
Public void onResume () {
System. Out.println (" todolist onresume!" );
super.onResume();
//init ();
}

Private void init () {
ListView=(listView) view. The findViewById (R.i d.l ist);
MySqliteDB mydb=new MySqliteDB (the getContext (), "mydb", null, 1);
SQLiteDatabase db=mydb. GetReadableDatabase ();
Cursor Cursor;
Cursor=db. Query (" todolist ", new String [] {" list_id ", "title", "total_time", "complete_time}", "user_id=" + uid, null, null, null, null);
ArrayList list=new ArrayList (a);
While (cursor. MoveToNext ()) {
//data into a map
Map map=new HashMap (a);
Final int t=cursor. Get int (cursor. GetColumnIndex (" total_time ")) - cursor. Get int (cursor. GetColumnIndex (" complete_time "));
If (t & gt; 0 {
Final int list_id=cursor. Get int (cursor. GetColumnIndex (" list_id "));
The map. The put (" title ", cursor. Get string (cursor. GetColumnIndex (" title ")));
The map. The put (" time ", t + "minutes");
//map is added to the collection list
list.add(map);
ListView. SetOnItemClickListener (new AdapterView. OnItemClickListener () {
@ Override
Public void onItemClick (AdapterView<?> The parent, View View, int position, long id) {
Intent intent=new Intent();
Bundle Bundle=new Bundle ();
Bundle. PutInt (" list_id "list_id);
Bundle. PutInt (" user_id ", uid);
Bundle. PutInt (" time ", t);
Bundle. PutString (" date ", the date);
Intent. PutExtras (bundle);
Intent. SetClass (getActivity (), Timing. The class).
GetActivity (). StartActivity (intent);
}
});
}
}
Adapter=new SimpleAdapter (getContext (), list, R.l ayout. Todolist_item,
New String [] {" title ", "time"}, new int [] {R.i which odolist_title, R.i which odolist_time});
ListView. SetAdapter (adapter);
}

Private void showDialog () {
//omitted here
}
}

CodePudding user response:

Is there a log can see,

CodePudding user response:

Describe the process of clear the Activity returns to the Fragment is to refresh the fragments of data but did not break out?
Please read the debug process go to take a look at your code

CodePudding user response:

refer to the second floor can reply wang:
describe the process of clear the Activity returns to the Fragment is to refresh the data fragments but didn't break out?
Please the debug process go take a look at your code to the
returning to fragments from the Activity to refresh the listVIew, but did not refresh and listVIew completely won't be displayed

CodePudding user response:

reference g_zq_leaner reply: 3/f
Quote: refer to the second floor can reply wang:

Describe the process of clear the Activity returns to the Fragment is to refresh the fragments of data but did not break out?
Please the debug process go take a look at your code to the
returning to fragments from the Activity to refresh the listVIew, but did not refresh and listVIew will not display completely


Debug the most effective, did you see your init logic, the list is empty
  • Related