ANDROID STUDIO Our objective in this chapter is to learn how to create images ba
ID: 3670594 • Letter: A
Question
ANDROID STUDIO
Our objective in this chapter is to learn how to create images based on user input. This will introduce us to the vast set of Canvasmethods at our disposal. Our project will require us to build a tutorial to help users visualize and add fractions via colored slices of pie. The app needs to generate random fractions for you to add. Aslo needs to generate a slice of pie that is equal to the fraction asked. One slice needs to be blue the other fraction red. The apps needs to look like the pic.
Explanation / Answer
There are two parts to this solution:
1) Code to generate random fractions
2) Represent the fraction using different colours in the form of pie chart.
Generate Random fraction:
import java.util.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class chooseRandom extends Activity
{
Button gr; //When this button is clicked, a random number is generated
TextView Result; // The generated number is visible here
Random R1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gr = (Button)findViewById(R.id.generate);
Result = (TextView)findViewById(R.id.randomresult);
gr.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View arg0)
{
String final = "";
String final2="";
String res;
R1= new Random();
for(int i = 0; i < 10; i++)
{
final= final+ String.valueOf(R1.nextInt()) + " ";
final2= final2+ String.valueOf(R1.nextInt()) + " ";
res=final+" / "+final2;
}
Result.setText(res);
}});
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.