我想输入3个数据来自3个EditText字段,它将要显示为条形图。如何将字符串值转换为整数数组列表 - Android
这是我的代码部分。给我一个这些错误的解决方案..
我试图让这个条形图使用这段代码。但它不起作用。我评论//错误点
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getfromdb);
final String[] mMonth = new String[] {
"Jan", "Feb" , "Mar", "Apr", "May", "Jun",
"Jul", "Aug" , "Sep", "Oct", "Nov", "Dec"
};
final EditText t1 =(EditText)findViewById(R.id.textView1);
final EditText t2 =(EditText)findViewById(R.id.textView2);
final EditText t3 =(EditText)findViewById(R.id.textView3);
Button btnChart = (Button) findViewById(R.id.btnView);
int x1 = Integer.parseInt(t1.getText().toString());
int x2 = Integer.parseInt(t2.getText().toString());
int x3 = Integer.parseInt(t3.getText().toString());
btnChart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openChart();
}
private void openChart() {
int x1 = Integer.parseInt(t1.getText().toString());
int x2 = Integer.parseInt(t2.getText().toString());
int x3 = Integer.parseInt(t3.getText().toString());
int[] x = { 0,1,2 };
int [] income = {x1 ,x2, x3}; //ERROR POINT
XYSeries incomeSeries = new XYSeries("Pulse Rate");
XYSeries expenseSeries = new XYSeries("");
for(int i=0;i
incomeSeries.add(i,income[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(incomeSeries);
dataset.addSeries(expenseSeries);
XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
incomeRenderer.setColor(Color.rgb(130, 130, 230));
incomeRenderer.setFillPoints(true);
incomeRenderer.setLineWidth(2);
incomeRenderer.setDisplayChartValues(true);
XYSeriesRenderer expenseRenderer = new XYSeriesRenderer();
expenseRenderer.setColor(Color.rgb(220, 80, 80));
expenseRenderer.setFillPoints(true);
expenseRenderer.setLineWidth(2);
expenseRenderer.setDisplayChartValues(true);
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setChartTitle("Pulse Chart");
multiRenderer.setXTitle("Pulse rate");
multiRenderer.setYTitle("Days");
multiRenderer.setZoomButtonsVisible(true);
for(int i=0; i< x.length;i++){
multiRenderer.addXTextLabel(i, mMonth[i]);
}
multiRenderer.addSeriesRenderer(incomeRenderer);
multiRenderer.addSeriesRenderer(expenseRenderer);
Intent intent = ChartFactory.getBarChartIntent(getBaseContext(), dataset, multiRenderer, Type.DEFAULT);
startActivity(intent);
}
});
}
private void setListAdapter(SimpleCursorAdapter adapter) {
// TODO Auto-generated method stub
}
我评论代码段中的//错误点。 当我给的值这点作为
int [] income = {60 ,40, 50}; //It should Be working
那么就应该工作。但是我希望把这些值使用的EditText框。
+0
您是否收到错误消息? –
2014-11-05 06:04:26
+0
以Integer []收入并尝试。 –
2014-11-05 06:04:32
+0
你确定你在编辑文本中输入t1.getText()。toString()后的价值 –
2014-11-05 06:06:41