An open API service indexing awesome lists of open source software.

https://github.com/sayed3li97/magic8ball-android

Simple Android Magic 8 Ball app. One Activity that displays a random prediction to answer the user question. The App randomly choose an answer from an array and display it to the user when the user clicks on the text in the middle of the screen.
https://github.com/sayed3li97/magic8ball-android

Last synced: about 1 year ago
JSON representation

Simple Android Magic 8 Ball app. One Activity that displays a random prediction to answer the user question. The App randomly choose an answer from an array and display it to the user when the user clicks on the text in the middle of the screen.

Awesome Lists containing this project

README

          

# Magic8Ball
Simple Android Magic 8 Ball app. One Activity displays a random prediction to answer the user question. The App randomly chooses an answer from an array and shows it to the user when they click on the text in the middle of the screen.

# Screenshots

# Step to re-create
1. Create a new project in Android Studio (Choose the Empty Activity)
2. Navigate to app/res/layout/activity_main.xml
3. Open the "TextView" and replace the XML code with the below code
```

```

4. Open the java file for the main Activity by opening the MainActivity.java from the following path app/java/"The first folder"/MainActivity.java
5. Replace the code in that file with the below code ("Don't remove the first line starting with the package")

```

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

//Declare the variable that will display and invoke the predictions
TextView textView;
//String array that will store a list of predictions
String[] predictions;
// Random object to choose from the list
Random random;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//specify the string array size
predictions = new String[20];

//Add all the predictions value
predictions[0] = "It is certain";
predictions[1] = "It is decidedly so";
predictions[2] = "Without a doubt";
predictions[3] = "Yes - definitely";
predictions[4] = "You may rely on it";
predictions[5] = "As I see it, yes";
predictions[6] = "Most likely";
predictions[7] = "Outlook good";
predictions[8] = "Yes";
predictions[9] = "Signs point to yes";
predictions[10] = "Reply hazy, try again";
predictions[11] = "Ask again later";
predictions[12] = "Better not tell you now";
predictions[13] = "Cannot predict now";
predictions[14] = "Concentrate and ask again";
predictions[15] = "Don't count on it";
predictions[16] = "My reply is no";
predictions[17] = "My sources say no";
predictions[18] = "Outlook not so good";
predictions[19] = "Very doubtful";

// Create new Random object to be used to predict
random = new Random();

//Connect the textView variable with the layout element
textView = (TextView) findViewById(R.id.textView);

//When the text view is clicked it will run the code inside
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Choose a random prediction and display it on the text view
textView.setText(predictions[random.nextInt(20)]);
}
});

}
}

```
Thank you!