gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:27 25 4
gpt4 key购买 nike

我想从 3 个 EditText 字段输入 3 个数据,它会显示为条形图。

这是我的代码部分。给我一个解决这些错误的方法..

我尝试使用此代码获取此条形图。但它不起作用。我评论了//ERROR POINT

   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<x.length;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

}

我在代码段中注释了//ERROR POINT。当我将这一点的值作为

    int [] income = {60 ,40, 50};             //It should Be working

那么它应该可以工作了。但是我想使用 EditText 框来放置这些值。

最佳答案

试试这条线

int x1 = Integer.parseInt(t1.getText().toString());

关于java - 如何将字符串值转换为整数数组列表 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26750679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com