androidplot 라이브러리를 사용하여 플롯 된 두 그래프의 Listview를 사용하고 있습니다. 새로운 수신 데이터가있을 때마다 listview를 지속적으로 업데이트하는 방법을 모르겠습니다.androidplot을 사용하여 그래프의 목록보기를 새로 고치는 방법
장치에서 연속적으로 임의의 데이터를받는 방법이 있습니다. 이 새로운 데이터로 두 그래프를 업데이트해야합니다. 아래에 나와있는 Array 어댑터에서 빌드 한 사용자 정의보기 어댑터를 사용합니다.
class MyViewAdapter extends ArrayAdapter<View> {
public MyViewAdapter(Context context, int resId, List<View> views) {
super(context, resId, views);
}
@Override
public int getCount() {
return 2;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
LayoutInflater inf = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = convertView;
if (v == null) {
v = inf.inflate(R.layout.listview_example_item, parent, false);
}
p = (XYPlot) v.findViewById(R.id.xyplot);
Random generator = new Random();
p.setTitle("plot" + pos);
for (int k = 0; k < NUM_SERIES_PER_PLOT; k++) {
double rl = Math.random();
double gl = Math.random();
double bl = Math.random();
double rp = Math.random();
double gp = Math.random();
double bp = Math.random();
if(setArrayValues != null){
if(pos == 0) {
XYSeries series = new SimpleXYSeries(setArrayValues.getSeries1Numbers(), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "RPM");
//XYSeries series = new SimpleXYSeries(nums, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "RPM");
p.addSeries(series, new LineAndPointFormatter(
Color.rgb(new Double(rl * 255).intValue(), new Double(gl * 255).intValue(), new Double(bl * 255).intValue()),
Color.rgb(new Double(rp * 255).intValue(), new Double(gp * 255).intValue(), new Double(bp * 255).intValue()),
null, null));
}
else{
XYSeries series = new SimpleXYSeries(setArrayValues.getSeries2Numbers(), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "SPEED");
//XYSeries series = new SimpleXYSeries(nums, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "SPEED");
p.addSeries(series, new LineAndPointFormatter(
Color.rgb(new Double(rl * 255).intValue(), new Double(gl * 255).intValue(), new Double(bl * 255).intValue()),
Color.rgb(new Double(rp * 255).intValue(), new Double(gp * 255).intValue(), new Double(bp * 255).intValue()),
null, null));
}
}
}
p.redraw();
return v;
}
}
아래의 방법은 장치에서 데이터를 수신하고 관련 Arraylists를 업데이트합니다.
public void receivePackage() throws SocketException {
new Thread() {
byte[] packet = new byte[64];
DatagramPacket data = new DatagramPacket(packet,
packet.length);
DatagramSocket socket = new DatagramSocket(null);
JSONObject json;
@Override
public void run() {
try {
isRunning = true;
socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(50009));
} catch (SocketException e1) {
e1.printStackTrace();
}
try {
while (isRunning) {
socket.receive(data);
final String string = new String(
data.getData(), 0,
data.getLength(), "UTF-8");
json = new JSONObject(string);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
int wiper = json.getInt("wiper");
int speed = json.getInt("speed");
speed = speed + 2000;
setArrayValues.addValues(wiper,speed);
lv.invalidateViews();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
socket.close(); // keep this out of while
}
}.start();
}
실제로 데이터 포인트를 그래프에 플로팅 할 수 없습니다. 나는 내가 선
XYSeries series = new SimpleXYSeries(setArrayValues.getSeries1Numbers(), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "RPM");
XYSeries series = new SimpleXYSeries(setArrayValues.getSeries2Numbers(), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "RPM");
에서 사용하지만 값이 그래프에 표시되지 않습니다 두 개의 서로 다른 ArrayLists에 값을 설정하는 별도의 헬퍼 클래스가
setArrayValues.addValues(wiper,speed);
을 사용했다. 이 문제에 대한 해결책을 제시 할 수 있습니까?
notifyDataSetChanged 메소드보기 -> http://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged() –