android数字转为字符串数组,如何将字符串值转换为整数数组列表 - Android

我想输入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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值