0

我有一个带有 android:onClick="getGraph" 的按钮,因此我在单击它时创建了一个函数,它检索位于 CheckByDate.java 的用户输入

public void getGraph (View view)
{
    tv = (TextView)findViewById(R.id.textView1);
    textDay = (EditText) findViewById(R.id.textDay);
    textMonth = (EditText) findViewById(R.id.textMonth);
    textYear = (EditText) findViewById(R.id.textYear);
    day = textDay.getText();
    month = textMonth.getText();
    year = textYear.getText();

    date = day + "/" + month + "/" + year;

    Intent dategraphintent = new Intent(CheckByDate.this, DateGraph.class);
    dategraphintent.putExtra("date", date);
    startActivity(dategraphintent);
}   

然后,在我的 DateGraph.java 中,我放了这样的东西

public Intent getIntent(Context context)
{
    String date;
    date = getIntent().getStringExtra("date");
       .
       .
       .
       .   //This is where the date will interact with my web service, then receive 
       .   //an array set of values, and plot as a graph
       .
       .
}

但是,我不知道,当我点击按钮时,它会强制关闭,我完全不知道,有什么想法吗?我试过用你的方法,还是我犯了一些愚蠢的错误??拜托我需要你的帮忙....

4

2 回答 2

2

你定义了你的方法

public Intent getthisIntent(Context context) {}

有一个参数,你调用它没有参数

getthisIntent();

你必须使用

getthisIntent(YourActivity.this);



然后按钮将值传递给新意图,并在没有新的 xxx.java 文件的情况下启动它?

当您不想拥有另一个Activity时,您想使用Intent什么?这毫无意义。如果您想Activity在单击时调用 new Button,则应使用以下代码段:

Intent i = new Intent(YourActivity.this, NewActivity.class);
startActivity(i);



我有一个按钮,这个按钮将从 EditText 中获取值,然后使用这个值来启动一个新的 Intent


gen.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {   
            day = textDay.getText().toString();
            month = textMonth.getText().toString();
            year = textYear.getText().toString();
            date = day + "/" + month + "/" + year;
            Intent i = new Intent(YourActivity.this, NewPlotActivity.class);
            i.putExtra("date", date);
            startActivity(i); // this will start new Activity where you plot a graph.
        }

然后,在您的NewPlotActivity中,您可以使用getIntent().getStringExtra("date");


注意:不要忘记添加<activity android:name=".NewPlotActivity"></activity>到您的Manifest.xml

于 2012-06-24T14:35:22.360 回答
0

你违反了你的方法签名!!,用上下文对象调用你的方法,使用:

getthisIntent(YourActivity.this);
getthisIntent(getApplicationContext());
于 2012-06-24T14:41:13.543 回答