alf*_*ibg 5 java android android-fragments android-fragmentactivity
我想在下面的代码中刷新或调用onCreateView.我有一个上下文来删除一个项目,之后我想用新项目刷新片段..谢谢!
public class ItemDetailFragmentBlackBoard extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
....
return rootView;
}
Run Code Online (Sandbox Code Playgroud)
}
/** 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;
}
Run Code Online (Sandbox Code Playgroud)
我解决了用自身替换片段的问题
代码是:
{
arguments.putString(ItemDetailFragmentBlackBoard.ARG_ITEM_ID, id);
ItemDetailFragmentBlackBoard fragment= new ItemDetailFragmentBlackBoard();
fragment.setArguments(arguments);
getFragmentManager().beginTransaction().replace(R.id.item_detail_container, fragment).commit();
}
Run Code Online (Sandbox Code Playgroud)
ItemDetailFragmentBlackBoard 是我的片段。我正在从 listView 中删除一个项目,删除它后,我用上面的代码重新调用我的片段,这样我就不会刷新!
| 归档时间: |
|
| 查看次数: |
10926 次 |
| 最近记录: |