我正在制作一个应用程序,我必须在其中从第一个活动获取项目名称和价格到另一个活动,我能够做到这一点,但在第二个活动中,我允许用户以数字形式输入数量,并且每当用户单击按钮 aTextView
以显示总金额,但无法计算项目的总金额。
我知道这是非常简单的任务,但是在按钮中写下这一行时出现错误onClick()
:
txtResult=txtCost*txtQty
我在这里放置第二个活动代码,
请更正这一点:-
public class SecondScreenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
TextView txtName = (TextView) findViewById(R.id.txtName);
TextView txtCost = (TextView) findViewById(R.id.txtCost);
EditText txtQty=(EditText)findViewById(R.id.txtQty);
Button btnClose = (Button) findViewById(R.id.btnCalculate);
TextView txtResult = (TextView) findViewById(R.id.txtResult);
Intent i = getIntent();
// Receiving the Data
String name = i.getStringExtra("name");
String cost = i.getStringExtra("cost");
// Displaying Received data
txtName.setText(name);
txtCost.setText(cost);
// Binding Click event to Button
btnClose.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Closing SecondScreen Activity
//finish();
txtResult=txtCost*txtQty;
}
});
}
}