所以我很早就问了一个关于如何通过单击按钮来更改文本视图的问题,效果很好!
所以现在......我将如何做到这一点,如果我有 1 个 textview 作为计数器,另一个作为限制,并且当计数器达到限制时,textview1 将返回 0 并且限制会增加。
我试过这个:
If (textViewCounter==textViewLimit);
textViewCounter.setText(0);
textViewLimit.setText(textViewLimit.getText().toString() + 100);
但这不起作用......我还能怎么做呢?
编辑我的问题只是一个例子。我打算用它来操纵我的价值观。但这就是一切:问题代码位于 btnBattle onClick 的底部
package com.example.intent_buttontests;
import android.app.Activity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
public class PlayScreen extends Activity {
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.play_screen);
String Name = getIntent().getStringExtra("strName");
TextView textview5 = (TextView) findViewById(R.id.textView5);
textview5.setText(Name);
textview5.setTextColor(Color.CYAN);
String Race = getIntent().getStringExtra("strRace");
TextView textViewStrRace = (TextView) findViewById(R.id.textViewStrRace);
textViewStrRace.setText(Race);
String Class = getIntent().getStringExtra("strClass");
TextView textViewStrClass = (TextView) findViewById(R.id.TextViewStrClass);
textViewStrClass.setText(Class);
String Alliance = getIntent().getStringExtra("strAlliance");
TextView textViewStrAlliance = (TextView) findViewById(R.id.textViewStrAlliance);
textViewStrAlliance.setText(Alliance);
Button btnInventory = (Button) findViewById(R.id.button1);
btnInventory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), Inventory.class);
startActivityForResult(intent, 0);
}
});
Button btnEquipment = (Button) findViewById(R.id.button2);
btnEquipment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), Equipment.class);
startActivityForResult(intent, 0);
}
});
Button btnStats = (Button) findViewById(R.id.button3);
btnStats.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), Statistics.class);
startActivityForResult(intent, 0);
}
});
Button btnShop = (Button) findViewById(R.id.Button01);
btnShop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), Shop.class);
startActivityForResult(intent, 0);
}
});
Button btnCrafting = (Button) findViewById(R.id.button4);
btnCrafting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), Crafting.class);
startActivityForResult(intent, 0);
}
});
Button btnClassTraining = (Button) findViewById(R.id.button5);
btnClassTraining.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), ClassTraining.class);
startActivityForResult(intent, 0);
}
});
Button btnBattle = (Button) findViewById(R.id.btnBattle);
btnBattle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method
// Definitions
Spinner spinnerMonsters = (Spinner) findViewById(R.id.spinnerMonsters);
TextView textViewBattleResults = (TextView) findViewById(R.id.textViewBattleResults);
TextView textViewXPValue = (TextView) findViewById(R.id.textViewXPValue);
TextView textViewXpNextLevel = (TextView) findViewById(R.id.textViewXpNextLevel);
// When XP limit is reached, increases by 100 and sets back to 0
if (textViewXPValue.getText().toString().equals(textViewXpNextLevel.getText().toString())); {
textViewXPValue.setText("0");
int newLimit = Integer.parseInt(textViewXpNextLevel.getText().toString()) + 100;
textViewXpNextLevel.setText(newLimit+"");
}
if (spinnerMonsters.getItemAtPosition(0).toString().equals("(0) Training Dummy")); {
textViewBattleResults.setText("You have killed Training Dummy for 10 experience points!");
i = i+10;
textViewXPValue.setText(String.valueOf(i));
}
}
});
}
}