I would like to refresh or call onCreateView in the code following . I have a contex menù to delete an Item and after I would like to refresh the fragment with the new Item.. Thanks at all!
public class ItemDetailFragmentBlackBoard extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
....
return rootView;
}
/** Menu on LongClick */
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Context Menu");
menu.add(0, v.getId(), 0, "Delete");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Delete"){
String status="";
AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
int posizione = info.position;
String[] messaggioDaCancellare= S.getMessaggiInfo().get(posizione);
try{
JSONObject del =ProxyUtils.proxyCall("deleteMessage",messaggioDaCancellare[4]);
status=del.getString("status");
} catch (Exception e) {
Log.i("Eccezione", e.toString());
}
Activity activity= getActivity();
if(status.equals("OK")){
**HERE......I would like to refresh my fragment o recall onCreateView method...**
Toast.makeText(activity, "Delete avvenuta", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(activity, "Delete non riuscita", Toast.LENGTH_SHORT).show();
}
} else {return false;}
return true;
}
It's better to define a viewGroup like a simple linearLayout (call it screen) in onCreateView function, and fill it in a function like init(). Each time you want to re-create your view, just remove all linearLayout's children and call init().
You did good job but it's more expensive than my simple solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With