2013-01-22 18 views
5

मैं निम्नलिखित कोड में रीफ्रेश या क्रिएटिव्यू को कॉल करना चाहता हूं। मेरे पास एक आइटम हटाने के लिए एक contex menù है और मैं नए आइटम के साथ खंड को रीफ्रेश करना चाहता हूं .. बिल्कुल धन्यवाद!क्रिएटिव्यू विधि को कैसे कॉल करें या मेरे टुकड़े को रीफ्रेश करें?

सार्वजनिक वर्ग ItemDetailFragmentBlackBoard फैली टुकड़ा {

@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; 
} 
+0

मैं क्या आप हटाने का प्रयास कर रहे हैं और क्या करते हैं आप – tyczj

+0

अद्यतन किया जा करना चाहते हैं लगता है कि आप शायद सिर्फ इसके बजाय एक अलग टुकड़ा स्थापित करना चाहते हैं ... –

उत्तर

2

मैं खुद के साथ मेरी समस्या मेरी fragmet replecing हल

कोड है:

{ 

    arguments.putString(ItemDetailFragmentBlackBoard.ARG_ITEM_ID, id); 
    ItemDetailFragmentBlackBoard fragment= new ItemDetailFragmentBlackBoard(); 
    fragment.setArguments(arguments); 
    getFragmentManager().beginTransaction().replace(R.id.item_detail_container, fragment).commit(); 
} 

ItemDetailFragmentBlackBoard मेरा टुकड़ा है। मैं सूची दृश्य से एक आइटम हटा रहा हूं और इसे हटाने के बाद मैं उपरोक्त कोड के साथ अपना टुकड़ा दोबारा कॉल करता हूं इसलिए मुझे ताज़ा नहीं मिलता है!

4

क्रिएटिव्यू फ़ंक्शन में एक सरल रैखिक Layout (इसे स्क्रीन पर कॉल करें) जैसे व्यू ग्रुप को परिभाषित करना बेहतर है, और इसे init() जैसे फ़ंक्शन में भरें। प्रत्येक बार जब आप अपना विचार फिर से बनाना चाहते हैं, तो बस सभी रैखिक Layout के बच्चों को हटाएं और init() को कॉल करें।

आपने अच्छा काम किया लेकिन यह मेरे सरल समाधान से अधिक महंगा है।

0
public class ItemDetailFragmentBlackBoard extends Fragment { 
    public static View _rootView; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    if (_rootView == null || _isRefreshDashboard) { 
     _rootView = inflater.inflate(R.layout.ItemDetailFragmentBlackBoard, container, false); 

     // your code can't be change without refreshFragment in here.. 

     _isDashboardRefresh = false; 
    } 
} 

// वैश्विक चर

public abstract class CommonBase extends AppCompatActivity { 
    public static boolean _isRefreshDashboard; 
} 

// रिफ्रेश अपने टुकड़ा

CommonBase._isRefreshDashboard = true;