I have made an variable Tweet inside first onClick event. I need to get that variable for another onClick event. Either variable Tweet or variable RandomIndex. I'm searching internet for two hours now, having problems to find how can I pass that variable. I understand that when OnClick event finishes, it kills the variable.
buttonWhatToDoNow.setOnClickListener(new View.OnClickListener() {
public int GetRandomNumber(int max) {
Random rand = new Random();
int num = rand.nextInt(max);
return num;
}
int RandomIndex;
public void onClick(View v) {
int countMax = databaseHelper.getCountNow();
RandomIndex = GetRandomNumber(countMax) + 1;
String Boolean = databaseHelper.getBoolean(RandomIndex);
if (Boolean == "1") {
RandomIndex = GetRandomNumber(countMax) + 1;
Boolean = databaseHelper.getBoolean(RandomIndex);
}
while (Boolean == "1") {
RandomIndex = GetRandomNumber(countMax) + 1;
Boolean = databaseHelper.getBoolean(RandomIndex);
}
String Title = databaseHelper.getTitleNow(RandomIndex);
String Text1 = databaseHelper.getText1Now(RandomIndex);
String Text2 = databaseHelper.getText2Now(RandomIndex);
String Text3 = databaseHelper.getText3Now(RandomIndex);
String Tweet = databaseHelper.getTweetNow(RandomIndex);
String Image1 = databaseHelper.getImage1Now(RandomIndex);
String Image2 = databaseHelper.getImage2Now(RandomIndex);
String Image3 = databaseHelper.getImage3Now(RandomIndex);
textViewDoThisTitle.setText(Title);
textViewDoThisText1.setText(Text1);
imageViewDoThis1.setImageResource(getResources().getIdentifier(
Image1, "drawable", getPackageName()));
textViewDoThisText2.setText(Text2);
imageViewDoThis2.setImageResource(getResources().getIdentifier(
Image2, "drawable", getPackageName()));
textViewDoThisText3.setText(Text3);
imageViewDoThis3.setImageResource(getResources().getIdentifier(
Image3, "drawable", getPackageName()));
}
public final int asddd = RandomIndex;
});
buttonTweetThis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, Tweet);
sendIntent.setType("application/twitter");
startActivity(Intent.createChooser(sendIntent, null));
}
});