如何使用GraphView库绘制stringbuilder值?

时间:2018-07-12 05:37:01

标签: android android-graphview

我有一个片段(Fragment2),它从其他具有蓝牙功能的设备接收温度值。我想绘制温度与时间的实时关系图。

温度值以StringBuilder的形式存储。例如:

{temp[0]=20, temp[1]=30,temp[2]=34,...

温度值必须为StringBuilder。但是,绘制图形方法需要使用双精度值,例如:

private void addEntry() {
         series.appendData(new DataPoint(lastX++, RANDOM.nextDouble() * 10d), true, 10);
       }

y值必须为两倍。我该如何解决这个问题?

我的代码:

public class Fragment2 extends Fragment {

    private View convertView;

    TextView incomingMessages;
    StringBuilder messages;
    StringBuilder [] temp = new StringBuilder[1000];
    Handler mHandler = new Handler();
    int LastPointX=0;
     int lasty;
     int x=0;
     int count=1000;

    LineGraphSeries<DataPoint> series;
    int index=0;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if(convertView==null){
            convertView=inflater.inflate(R.layout.fragment_fragment2, container, false);
            incomingMessages= (TextView) convertView.findViewById(R.id.text);
            messages =new StringBuilder();
            LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, new IntentFilter("incomingMessage"));
        }
        return convertView;
    }
    BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String text=intent.getStringExtra("theMessage");
            messages.append(text+"\n");
            incomingMessages.setText(messages);
            temp[index]= new StringBuilder(messages);
            Log.d("deneme", "message:"+messages+"\n"+"temp"+temp[index]);
            index++;

            messages.delete(0, messages.length());
            Log.d("temp0",temp[0]+"temp1"+temp[1]+"\n"+"temp2"+temp[2]);
        }
    }
}

0 个答案:

没有答案