2012-06-05 3 views
0

고전적인 메뉴/세부 조각 태블릿 활동을 구축 중입니다.View 개체로 조각을 새로 고치는 방법

내 세부 정보 조각은 외부 라이브러리에 의해 생성되는 그래프입니다. 이 라이브러리는 나에게 그래프의 의도 또는 전망을 제공합니다.

내 메뉴를 클릭하면 그래프가 새로 고침됩니다.

이 내 활동 코드입니다 : 내가의 loadGraph 기능으로 조각보기를 다시로드 할 수있는 경우

public class GraphFragment extends Fragment { 

private Context context; 
private Graphical graphical; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    context = this.getActivity(); 
    graphical = new Graphical(); 

    View graphView = null; 
     graphView = graphical.executeForView(context, UrlAction.CONSO_WEEKS); 
    return graphView; 
} 

public View loadGraph(UrlAction urlAction) { 
    Log.d("GraphFragment","[loadGraph] START"); 
    View graphView = graphical.executeForView(context, urlAction); 
      //This graphView contains the graph I want to display in my graphFragment 
    return graphView; 
} 
} 

나도 몰라 : 이것은 내 세부 조각 코드가

public class myActivity extends FragmentActivity { 

Context context; 
Graphical graphical; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    context = this; 
    setContentView(R.layout.fragment_suivi_conso_graph); 
} 

/** 
* Called when clicking on the menu Fragment 
*/ 
public void onChooseGraph(UrlAction urlAction){ 
    GraphFragment graphFragment = (GraphFragment)       getSupportFragmentManager().findFragmentById(R.id.graph_fragment); 

    if (graphFragment == null || !graphFragment.isInLayout()) { 
     Intent intentGraph; 
    intentGraph = graphical.executeForIntent(this, urlAction); 
    startActivity(intentGraph); 
    } 
    else { 
     View graphView = graphFragment.loadGraph(urlAction); 
      // I don't know what to do with this View ! 
    } 
} 

입니다 조각. 또는 GooseGraph 기능으로 활동을 수행해야합니까?

두 경우 모두 새로 고침하는 방법을 알지 못합니다.

내 세부 조각에 : GraphFragment, 여기에 적절한 loadGraph 메도 :

public void loadGraph(UrlAction urlAction) { 
    Log.d(TAG,"[loadGraph] START, for urlAction : " + urlAction); 

    View graphView = null; 
    try { 
     graphView = graphical.executeForView(context, urlAction); 
    } catch (Exception e) { 
     Log.e(TAG, "[loadGraph] Error during Parsing : "+e.getMessage()); 
     e.printStackTrace(); 
     if(e.getMessage().equals(XmlParserSuivitConso.XML_IS_ERROR)){ 
      Toast.makeText(context, getString(R.string.checkYouParameters), Toast.LENGTH_LONG).show(); 
      Intent intentSettings = new Intent(context, SettingsActivity.class); 
      startActivity(intentSettings); 
      getActivity().finish(); 
     } 
    } 

    setFragmentContentView(graphView); 
} 

void setFragmentContentView(View view) { 
    LinearLayout.LayoutParams layoutParams = 
      new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 
              ViewGroup.LayoutParams.FILL_PARENT); 
    mRootLayout.removeAllViews(); 
    mRootLayout.addView(view, layoutParams); 
} 

그리고 활동 내가 loadGraph를 호출하려면 다음 코드를 사용하고 myActivity에 :

답변

0

나는 해결책을 발견
public void onChooseGraph(UrlAction urlAction){ 
    GraphFragment graphFragment = (GraphFragment) getSupportFragmentManager().findFragmentById(R.id.graph_fragment); 
    // On essaye de récupérer notre fragment. 

    // S'il n'est pas présent, on le crée en lançant son Activity 
    if (graphFragment == null || !graphFragment.isInLayout()) 
    { 
     Intent intentGraph; 
     try { 
      intentGraph = graphical.executeForIntent(this, urlAction); 
      startActivity(intentGraph); 
     } catch (Exception e) { 
      Log.e(TAG, "[onListItemClick] Error during Parsing : "+e.getMessage()); 
      e.printStackTrace(); 
      if(e.getMessage() == null || e.getMessage().equals(XmlParserSuivitConso.XML_IS_ERROR)){ 
       Toast.makeText(this, getString(R.string.checkYouParameters), Toast.LENGTH_LONG).show(); 
       Intent intentSettings = new Intent(this, SettingsActivity.class); 
       startActivity(intentSettings); 
       finish(); 
       return; 
      } 
     } 
    } 
    else 
    // Sinon on met à jour le choix de l'utilisateur 
    { 
     graphFragment.loadGraph(urlAction); 
    } 

내가 도움이 되었기를 바랍니다.

관련 문제