所以我正在制作一个像应用程序一样的火种我正在做一个硬币系统,其中一个用户默认有20个硬币,然后他向右滑动1个硬币将被添加到总数中,我正在使用edittext来显示硬币金额,我读了关于如何将字符串转换为int的文章,但它似乎没有帮助,应用程序崩溃后,我做了大多数文章说我需要做的,这是我的一些代码,谢谢!
private DatabaseReference usersDb;
ListView listView;
List<cards> rowItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCoins = (EditText) findViewById(R.id.coins);
String myEditValue = mCoins.getText().toString();
final int myEditNum = Integer.parseInt(myEditValue);
usersDb = FirebaseDatabase.getInstance().getReference().child("Users");
mAuth = FirebaseAuth.getInstance();
currentUId = mAuth.getCurrentUser().getUid();
checkUserSex();
rowItems = new ArrayList<cards>();
arrayAdapter = new arrayAdapter(this, R.layout.item, rowItems );
SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
flingContainer.setAdapter(arrayAdapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
@Override
public void removeFirstObjectInAdapter() {
Log.d("LIST", "removed object!");
rowItems.remove(0);
arrayAdapter.notifyDataSetChanged();
}
@Override
public void onLeftCardExit(Object dataObject) {
cards obj = (cards) dataObject;
String userId = obj.getUserId();
usersDb.child(userId).child("connections").child("nope").child(currentUId).setValue(true);
Toast.makeText(MainActivity.this, "Left", Toast.LENGTH_SHORT).show();
}
@Override
public void onRightCardExit(Object dataObject) {
cards obj = (cards) dataObject;
String userId = obj.getUserId();
usersDb.child(userId).child("connections").child("yeps").child(currentUId).setValue(true);
isConnectionMatch(userId);
Toast.makeText(MainActivity.this, "Right", Toast.LENGTH_SHORT).show();
mCoins.setText(myEditNum+ "1");
}
`
答案 0 :(得分:0)
通过这种方式连接
myEditNum+ "1"
将您的字符串和int移动到onRightCardExit方法,并将总和:
String myEditValue = mCoins.getText().toString();
final int myEditNum = Integer.parseInt(myEditValue);
mCoins.setText(String.valueOf(myEditNum+1));