Je veux appuyer sur le bouton [Créer nouveau suiveur] et il incrémente le textview dans followers.xml par un, chaque fois que le bouton est pressé.Comment mettre à jour un TextView dans un fichier XML différent avec un bouton de MainActivity.class?
Voici mon 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`
La question que je vais avoir est que je veux que le bouton pour incrémenter un textview par un à chaque fois sur le bouton de l'activité principale est pressée.
double possible de [ Comment puis-je transmettre des données entre les activités de l'application Android?] (Http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-app lication) – Titus
si 'followers.xml' est lié à une autre activité ou fragment? – Redman