2012-09-05 25 views
2

我對android世界很陌生,來自許多服務器端編程的背景。非常小的Java。在片段內調用acharengine

我正在開發一個應用程序,我需要兩個片段,一個顯示導航的左側,一個顯示內容。 我的第一個主要挑戰是使一個導航鏈接使用acharengine打開圖表。

我從achartengine,我一直在關注這裏的例子:achartengine example

我一直在下面通過谷歌這裏提供的Android開發應用演示:Fragment Basics

我使用的例子,簡單地建立一切使用現有的代碼。到目前爲止,我縮小了實際的內容顯示到裏面ArticleFragment.java此代碼:

這是發生了什麼在onStart:

public void onStart() { 
    super.onStart(); 

    // During startup, check if there are arguments passed to the fragment. 
    // onStart is a good place to do this because the layout has already been 
    // applied to the fragment at this point so we can safely call the method 
    // below that sets the article text. 
    Bundle args = getArguments(); 
    if (args != null) { 
     // Set article based on argument passed in 
     updateArticleView(args.getInt(ARG_POSITION)); 
    } else if (mCurrentPosition != -1) { 
     // Set article based on saved instance state defined during onCreateView 
     updateArticleView(mCurrentPosition); 
    } 
} 

public void updateArticleView(int position) { 

    TextView article = (TextView) getActivity().findViewById(R.id.article); 
    article.setText(Ipsum.Articles[position]); 
    System.out.println("Position: " + position); 
    mCurrentPosition = position; 
} 

這裏面是什麼Ipsum.java:

package com.example.android.fragments; 

公共類存有{

static String[] Headlines = { 
    "Link One", 
    "Link Two", 
    "Link Three" 
}; 


static String[] Articles = { 
    "Link One\n\n Some Text...", 
    "Link Two\n\n Some Text...", 
    "Link Three\n\n Some Text..." 
}; 

}

當您單擊其中一個「鏈接」時,我希望圖表顯示在其他片段內。 我確信這很簡單,並且由於缺乏語法知識,我嘗試將updateArticleView中的代碼修改爲textViews,但成功有限。

我嘗試過搜索,並且已經有了一些有用的例子,但它們都是從確切知道他/她在做什麼的人的角度出發的。我是這個品牌的新手(3個星期左右),所以請爲我貶低它。謝謝。

回答

1

您可以在YouTube上搜索AChartEngine,並在那裏找到一些關於如何開始使用圖表庫的視頻教程。

我還建議你看看官方AChartEngine演示here

此外,爲了解決您的問題,爲了弄清楚如何將圖表與其他組件一起嵌入視圖中,請參閱此post

+0

我應該在原帖(我必須忘記)中提到我已經使用了您鏈接到的AChartEngine演示。我跑了幾個版本。雖然他們的演示是有用的,但除代碼外沒有其他文檔。這讓新手難以入手。但感謝回覆,這篇文章可能會有所幫助。 – Ryan

5

在這個問題上花了數小時後,我終於在GitHub上找到了答案。

請去here,導航到/src/org/elasticdroid/fragments/ChartFragment.java就是這樣。

你可以很容易地複製/粘貼這段代碼,並且很少玩這個代碼會很好用。