我遇到了我的函数是追加而不是添加的问题。
例如,我希望我的结果从200上升到201,但实际上是200到2001。有什么想法吗?
btnQuickUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //ref 1
mAthlete_etCompScore = (EditText) findViewById(R.id.tvAttent);
quickUpdate = String.valueOf(mAthlete_etCompScore.getText().toString());
quickUpdate = quickUpdate + 1;
Book book = new Book();
book.setAuthor(quickUpdate);
答案 0 :(得分:0)
使quickUpdate Integer变量不是String,它将起作用
答案 1 :(得分:0)
这是因为fos_rest:
allowed_methods_listener: true
serializer:
serialize_null: true
body_listener:
array_normalizer: fos_rest.normalizer.camel_keys
body_converter:
enabled: true
disable_csrf_role: ROLE_API
format_listener:
rules:
- { path: '^/sso/menu', priorities: ['html'], fallback_format: 'html', prefer_extension: false }
- { path: '^/public/request-password', priorities: ['html'], fallback_format: 'html', prefer_extension: true }
- { path: '^/', priorities: ['json'], fallback_format: 'json', prefer_extension: false }
routing_loader:
default_format: json
include_format: false
view:
view_response_listener: true
formats:
json: true
xml: false
rss: false
html: true
mime_types:
json: ['application/json', 'application/x-json']
jsonp_handler: false
exception:
enabled: true
是quickUpdate
。
改为使用String
。
答案 2 :(得分:0)
您必须将quickUpdate
声明为int
并更改为:
quickUpdate = Integer.parseInt(mAthlete_etCompScore.getText().toString());
quickUpdate = quickUpdate + 1;
答案 3 :(得分:0)
在进行任何数学操作之前,您需要转换为字符串。
btnQuickUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //ref 1
mAthlete_etCompScore = (EditText) findViewById(R.id.tvAttent);
//get your text into a string variable
String str_quickUpdate =
String.valueOf(mAthlete_etCompScore.getText().toString());
//Convert the string to integer value
int quickUpdate = Integer.parseInt(str_quickUpdate.trim());
//Your increment here
quickUpdate = quickUpdate + 1;
Book book = new Book();
book.setAuthor(quickUpdate);