机器人 - 如何使用用户数据图 [英] android - how to make plot with user data

查看:122
本文介绍了机器人 - 如何使用用户数据图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个计划,使根据用户数据的一些计算。
该程序工作正常,但是当我尝试为了使情节使用achartengine,它崩溃。(不会做图)

I have a program which makes some calculations according to user data. The program works fine ,but when i try to use achartengine in order to make the plot ,it crashes.(doesn't do the plot)

我不知道我是否正确传递中的数据线图类。

I am not sure if i am passing right the data in the LineGraph class.

据我了解,我必须用

包某事= getIntent.getExtras()
  但我不知道在哪里把它放在线图。

"Bundle sth=getIntent.getExtras()" but i am not sure where to put it in LineGraph.

我有在其中用户输入的数据,然后presses计算按钮,而在另一个活动显示结果的number_cores类。
在这方面,我有:

I have the number_cores class which in which the user enters the data and then presses the calculate button and in another activity shows the result. In this , i have :

public void cores_func(){
             double initcores=Double.parseDouble(num_cores.getText().toString().trim());
             double half_time=Double.parseDouble(halftimecores.getText().toString().trim());
             double ttime=Double.parseDouble(timecores.getText().toString().trim());
             double l=Math.log(2)/half_time;
             double fcores=initcores*Math.exp(-l*ttime);


             Intent i=new Intent(this,core_calcs.class);
             i.putExtra("value",fcores);
             i.putExtra("value2",initcores);
             startActivity(i);  
         }

然后,在core_calcs类(你可以从上面的意图看),我显示的结果,也是我加入,当用户单击此按钮,显示了图(现在,它崩溃这里)。

Then , in the core_calcs class (as you can see from the intent above) , i show the result and also i added a button which when the user clicks it ,shows the graph (right now ,it crashes here).

我在onCreate方法(core_calcs):

I have (core_calcs) in the onCreate method :

double fcores=getIntent().getExtras().getDouble("value");
        double initcores=getIntent().getExtras().getDouble("value2");

和则:

 public void onClick(View v) {
    switch (v.getId()){
    case R.id.show_cores_graph:
        double fcores=getIntent().getExtras().getDouble("value");
        double initcores=getIntent().getExtras().getDouble("value2");
        Intent i = new Intent();        
        i.setClassName("com.wordpress.androiddevgeo.Radiation",LineGraph.class.getName());                 
        i.putExtra("value", fcores);
        i.putExtra("value2", initcores);
        this.startActivity(i);  
        break;
      }      
    }

(另外,我有公共无效LineGraphHandler(查看视图)这里)

(also, i have the public void LineGraphHandler (View view) here)

最后,在线图的类(上述的意图):

Finally , in the LineGraph class (the intent above):

public class LineGraph extends Activity {

public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);

    Bundle extras=getIntent().getExtras();
    String fcores=extras.getString("value");
    String initcores=extras.getString("value2");
}



public Intent getIntent(Context context){

    //double ttime=getIntent(context).getExtras().getDouble("value");

    double [] x = {0,100};           //time axis
    double [] y = {initcores,fcores};  //number of cores axis

    TimeSeries series = new TimeSeries("Number of cores");
    for (int i=0;i<x.length;i++){
        series.add(x[i],y[i]);
    }

    XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
    dataset.addSeries(series);

    XYMultipleSeriesRenderer mRenderer =new XYMultipleSeriesRenderer();
    XYSeriesRenderer renderer =new XYSeriesRenderer();
    mRenderer.addSeriesRenderer(renderer);

    Intent intent=ChartFactory.getLineChartIntent(context, dataset, mRenderer,"Decay");

    return intent;

      }
       }

如何将数据(initcores和fcores)传递到线图?

How to pass the data (initcores and fcores ) to the LineGraph?

--------错误消息------------------------------------- --------

--------Error messages ---------------------------------------------

W / dalvikvm(734):主题ID = 3:螺纹未捕获的异常退出

W/dalvikvm(734): threadid=3: thread exiting with uncaught exception

(组= 0x4000fe70)01-15 18:42:01.334:E / AndroidRuntime(734):未捕获
  处理:螺纹主力退出,由于未捕获的异常

(group=0x4000fe70) 01-15 18:42:01.334: E/AndroidRuntime(734): Uncaught handler: thread main exiting due to uncaught exception

E / AndroidRuntime(734):android.content.ActivityNotFoundException:无法找到明确的活动类

E/AndroidRuntime(734): android.content.ActivityNotFoundException: Unable to find explicit activity class

有你在你的Andr​​oidManifest.xml宣布这项活动?

have you declared this activity in your AndroidManifest.xml?

(我已宣布了线图,也有org.achartengine.GraphicalActivity活动)
谢谢!

(I have declared the activity for the LineGraph and also "org.achartengine.GraphicalActivity") Thanks!

推荐答案

捆绑的方式:

Intent searchIntent = new Intent();        
searchIntent.setClassName("com.mypackage",searrchActivity.class.getName());                 
searchIntent.putExtra("value", initcores); // key/value pair, where key needs current package prefix.                   
searchIntent.putExtra("value2", fcores);
thisactivity.startActivity(searchIntent);  

和你的线图的活动:

class LineGraph extends Activity{
   private Double initcores;
   private Double fcores;

   public Double getInitcores(){ return this.initcores;} 
   public void setInitcores(Double initcores){ this.initcores=initcores;} 
   public Double getFcores(){ return this.fcores;} 
   public void setFcores(Double fcores){ this.fcores=fcores;} 


   public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    ......
    Bundle extras = getIntent().getExtras(); 
    Double initcores= extras.getDouble("value"); 
    setInitcores(initcores); 
    Double fcores= extras.getDouble("value2"));
    setFcores(fcores);

    }
  public Intent getIntent(...){
                  Double initcores= getInitcores();
                  Double fcores= getFcores();
           //yourcode 
  }
}

共享preferences方式:

SharedPreferences approach:

    SharedPreferences sp =PreferenceManager.getDefaultSharedPreferences(this);      
    SharedPreferences.Editor ed= sp.edit();
    ed.putInt("screen_width", 480);     
    ed.commit();        

在你的下一个活动。

and in your next activity

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    int width = sp.getInt("screen_width",default_int_value);

希望这有助于升技

hope this helps abit

这篇关于机器人 - 如何使用用户数据图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆