0

クラシック メニュー/詳細フラグメント タブレット アクティビティを作成しています。

私の詳細フラグメントは、外部ライブラリによって生成されたグラフです。このライブラリは、インテントまたはグラフのビューを提供しています。

メニューをクリックすると、グラフを更新したいと思います。

これは私のアクティビティコードです:

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 !
    }
}

これは私の詳細フラグメントコードです:

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;
}
 }

フラグメント ビューをフラグメントのloadGraph関数にリロードできるかどうかわかりません。または、アクティビティでonChooseGraph関数にそれを行う必要がありますか。

どちらの場合も、更新方法がわかりません。

4

1 に答える 1

0

私は解決策を見つけました:

私の詳細フラグメントでは: 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);
}

アクティビティmyActivityでは、次のコードを使用して呼び出していますloadGraph

    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);
    }

私はそれが誰かを助けることを願っています!

于 2012-07-10T10:23:29.073 に答える