私は私の中にある を持ってHandler
いMainActivity
ます。これは、のレイアウト内にある のHandler
1 つの UI を更新する必要があります。Fragment
MainActivity
次に、ループを持つ別のクラスがあります。このクラスを作成したら、それを呼び出してmyLooper
何らかの計算を行い、ループ内の情報をHandler
myに送信しますMainActivity
。次に、そのデータを、GraphView
私MainActivity
のフラグメント内に実装した に更新します。
フロー: ステップ 1: でデータを計算しますMyLooper
。ステップ 2: MainActivity
my 経由で にデータを送信しますHandler
。ステップ 3:送信されたデータを更新Handler
しMainActivity
ます。Fragment
GraphView
関連コード:
public class MainActivity extends ActionBarActivity implements
ActionBar.TabListener {
public MyLooper myDataLooper;
Fragment graphFrag = fragment_graphpage.newInstance(1);
public final Handler myHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
((fragment_graphpage) graphFrag).updateGraphUI(msg.getData().getFloat("myvoltage"));
}
};
SectionsPagerAdapter mSectionsPagerAdapter;
globalControlInstance globalControl;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
globalControl = globalControlInstance.getInstance();
myDataLooper = (IOIOBoard) getApplicationContext();
myDataLooper.create(getBaseContext(), this,_myIOIOHandler);
myDataLooper.start();
}
MyLooper クラス:
public class MyLooper extends Application implements IOIOLooperProvider {
globalControlInstance globalData = globalControlInstance.getInstance();
public AnalogInput AI1;
public Handler IOIOHandler;
private final IOIOAndroidApplicationHelper helper_ = new IOIOAndroidApplicationHelper(
this, this);
protected void create(Context myContext, Activity myActivity, Handler myHandler) {
IOIOHandler = myHandler;
helper_.create();
}
protected void destroy() {
helper_.destroy();
}
protected void start() {
helper_.start();
}
protected void stop() {
helper_.stop();
}
protected void restart() {
helper_.restart();
}
class Looper extends BaseIOIOLooper {
@Override
protected void setup() throws ConnectionLostException {
}
@Override
public void loop() throws ConnectionLostException, InterruptedException {
Message myVoltageMessage = new Message();
Bundle myVoltageBundle = new Bundle();
myVoltageBundle.putFloat("myvoltage", AI1.getVoltage());
myVoltageMessage.setData(myVoltageBundle);
IOIOHandler.sendMessage(myVoltageMessage);
}
}
@Override
public IOIOLooper createIOIOLooper(String connectionType, Object extra) {
return new Looper();
}
}
最後に、Fragment
私GraphView
のupdateGraphUI
メソッドを含む .:
public void updateGraphUI(float newReading) {
final double newReadingDouble = newReading;
mTimer2 = new Runnable() {
@Override
public void run() {
graphLoopCounter++;
if (globalData.isLiveUpdatingEnabled()) {
alarmCheck(newReadingDouble);
globalData.setGraph2LastXValue(globalData
.getGraph2LastXValue() + 1d);
globalData.getGraphViewSeries().appendData(
new GraphViewData(globalData.getGraph2LastXValue(),
newValue), true, 1000);
if (globalData.getGraphPeak() < newReadingDouble) {
globalData.setGraphPeak(newReadingDouble);
graphPeak.setText("Graph Peak: "
+ Double.toString(newReadingDouble));
}
avgSum += globalData.getLatestGraphData();
graphAvg.setText("Graph Avg: " + Double.toString(avgSum/graphLoopCounter));
mHandler.postDelayed(this, 100);
}
}
};
mHandler.postDelayed(mTimer2, 100);
}
どこに myの実装のmHandler
ハンドラーがあります。とはFragment
両方ともmTimer1
sです。mTimer2
Runnable
私の問題は; 何をしようとしても、データはGraphViewに送信されず、更新されません...