我想按下[创建新关注者]按钮,每按一次按钮,它会将 followers.xml 中的 textview 增加1。
这是我的MainActivity.class
package com.couchmango.godslife;
import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import java.util.*;
import android.preference.*;
public class MainActivity extends Activity implements OnClickListener
{
//Declare Constant Variables
private Button createFollowerButton;
private int followerLimit;
private boolean reachedFollowerLimit;
public static int FollowerCount;
public static TextView numberOfFollowers;
//Called when activity opens
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Create Button
createFollowerButton = (Button)findViewById(R.id.createFollowerButton);
createFollowerButton.setOnClickListener(this);
numberOfFollowers = (TextView) findViewById(R.id.numberOfFollowers);
};//End onCreate
@Override
public void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
}
@Override
public void onClick(View v)
{
switch(v.getId()){
//Milestones Button Pressed
case R.id.milestones:Intent intent = new Intent(MainActivity.this, milestones.class);
MainActivity.this.startActivity(intent);
break;
//God Stats Button Pressed
case R.id.godStats:intent = new Intent(MainActivity.this, godStats.class);
MainActivity.this.startActivity(intent);
break;
//Influence Button Pressed
case R.id.influence:intent = new Intent(MainActivity.this, influence.class);
MainActivity.this.startActivity(intent);
break;
//Followers Button Pressed
case R.id.followers:intent = new Intent(MainActivity.this, followers.class);
MainActivity.this.startActivity(intent);
break;
//Create Follower Button Pressed
case R.id.createFollowerButton:
numberOfFollowers = (TextView) numberOfFollowers;
FollowerCount++;
if(reachedFollowerLimit == false){AddFollower();}
if(followerLimit == 10){
reachedFollowerLimit = true;
Context context = getApplicationContext();
CharSequence toastText = "Follower limit reached";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, toastText, duration);
toast.show();
}//end if()
break;
}//END SWITCH
}//End OnCLICK
//Adds Follower
//everytime button is clicked
public final void AddFollower()
{
followerLimit++;
FollowerCount++;
}//End names()
private class Follower
{
int influence;
public Follower(int influence)
{
influence = 1;
}
}
public void startWorshipping()
{
}
}//End MainActivity`
我遇到的问题是,每当按下主活动上的按钮时,我希望按钮将文本视图增加1。