不要运行方法,或显示textview和复选框文本

时间:2013-01-09 01:53:55

标签: android checkbox textview

当我玩游戏时,运行chooseSubject和ChooseQuestion方法,但它不显示它为什么这样做?是不是它没有运行方法,还是方法写得不正确?我可以解决这个问题,我确保它们具有相同的ID并且它们存在并且它们存在,所以不确定它为什么不起作用。

package com.ultimanaire;



import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class GameActivity extends Activity {

CheckBox answer_1;
CheckBox answer_2;
CheckBox answer_3;
CheckBox answer_4;
CheckBox[] cbc = {answer_1, answer_2, answer_3, answer_4};

Map<String, Boolean> subjectExhausted = new HashMap<String, Boolean>();
String[] SubjectSelected;

Question history0 = new Question("Whose assassination caused World War I?", new String[]{"Wilhelm I", "Franco", "David Lloyd George", "Franz Ferdinand"}, false, "history");
Question history1 = new Question("Which event put Japan on the world map as a major world power?", new String[]{"WWI", "WWII", "Korean-Japanese War", "Meiji Restoration"}, false, "history");
Question history2 = new Question("What Mesoamerican civilization was destroyed by Pizarro?", new String[]{"Aztecs", "Maya", "Ottawa", "Incas"}, false, "history");
Question math0 = new Question("What is the limit of x as it approaches infinite of (5x^2 - 3)/(52 - 3x^2)?", new String[]{"Infinite", "Non-real Answer", "5/3", "-5/3"}, false, "math");
Question math1 = new Question("Solve for x: 2^x-10=-6", new String[]{"4", "1", "0", "2"}, false, "math");
Question math2 = new Question("Who invented the sum formula for arithmetic sequences?", new String[]{"Euler", "Heisenberg", "Einstein", "Gauss"}, false, "math");
Question science0 = new Question("What are valence electrons?", new String[]{"The innermost electrons of an atom", "The innermost electrons of a molecule", "The outermost electrons of a molecule", "The outermost electrons of an atom"}, false, "science");
Question science1 = new Question("What type of rock forms under high heat and pressure?", new String[]{"igneous", "Sedimentary", "Weathered", "Metamorphic"}, false, "science");
Question science2 = new Question("What is the process by which species mutate over generations and thus survive better and proliferate better?", new String[]{"Adaptation", "Change", "Chronic Adaptation", "Evolution"}, false, "science");
Question fl0 = new Question("What is the French word for \"why\"?", new String[]{"Quoi", "Comment", "Que", "Pourquoi"}, false, "fl");
Question fl1 = new Question("What is the French word for \"help\"?", new String[]{"Attendre", "Ayuda", "Où", "Aider"}, false, "fl");
Question fl2 = new Question("What is the subjunctive singular first-person form of être (a French verb)?", new String[]{"est", "suis", "pour", "sois"}, false, "fl");
Question fl3 = new Question("The passé composé in French involves two verbs: ______ or ______ and the past participle of the conjugated verb.", new String[]{"faire, être", "avoir, aller", "suivre, aller", "avoir, être"}, false, "fl");
Question fl4 = new Question("What is the capital of Spain?", new String[]{"Barcelona", "Spain City", "Lisbon", "Madrid"}, false, "fl");
Question fl5 = new Question("What is the Spanish word meaning \"to hold\"?", new String[]{"Lanzar", "Tomar", "Esperar", "Mantener"}, false, "fl");
Question fl6 = new Question("In German, there are four cases. Which of the following isn't one of them?", new String[]{"Dative", "Genitive", "Nominative", "Locative"}, false, "fl");
Question fl7 = new Question("What is the Spanish direct object form of \"me\"?", new String[]{"yo", "a yo", "a me", "me"}, false, "fl");
Question fl8 = new Question("In French, which of the following is considered a literary tense?", new String[]{"passé composé", "subjonctif", "imparfait", "passé simple"}, false, "fl");
Question fl9 = new Question("Translate this sentence into French: \"I like neither apples nor potatoes.\"", new String[]{"J'aime ni pommes ni pommes de terre.", "Je n'aime pas les pommes ou les pommes de terre.", "Je déteste les pommes et les pommes de terre.", "Je n'aime ni pommes ni pommes de terre."}, false, "fl");
Question fl10 = new Question("What is the capital of Côte d'Ivoire?", new String[]{"Séguéla", "Daloa", "Aboisso", "Yamoussoukro"}, false, "fl");
Question fl11 = new Question("Translate the following sentence into English: \"Je me trouve au centre-ville.\"", new String[]{"I find myself in the middle of the village.", "I'm located in the middle of the village.", "I'm in the center of the city.", "I'm in downtown."}, false, "fl");
Question fl12 = new Question("Which of the following accents does not occur regularly in French?", new String[]{"grave", "acute", "circumflex", "caron"}, false, "fl");
Question fl13 = new Question("Which of the following accents does not occur regularly in Spanish?", new String[]{"tilde", "grave", "acute", "circumflex"}, false, "fl");
Question fl14 = new Question("The passé simple of avoir in French (the nous form) is:", new String[]{"avions", "aurons", "eûtes", "eûmes"}, false, "fl");
Question fl15 = new Question("What is the German word for \"strange\"?", new String[]{"Neugierig", "Verrückt", "Warum", "Seltsam"}, false, "fl");
Question fl16 = new Question("German has the following grammatical genders:", new String[]{"Feminine, Masculine", "It has none, like English.", "Common, Neuter", "Feminine, Masculine, Neuter"}, false, "fl");
Question fl17 = new Question("In German, what is the second-person informal preterite subjunctive form of \"haben\"?", new String[]{"hast", "hattest", "habest", "hättest"}, false, "fl");
Question fl18 = new Question("In Spanish, a direct object pronoun", new String[]{"goes after the conjugated verb.", "goes at the end of a clause.", "begins a sentence.", "comes before the conjugated verb."}, false, "fl");
Question fl19 = new Question("What is the Spanish equivalent of the English phrase \"make sense\"?", new String[]{"hacer sentido", "crear sentido", "establecer sentido", "tener sentido"}, false, "fl");

Question history3 = new Question("Which English king established the Anglican Church for mainly personal reasons?", new String[]{"Charles I", "William III", "Edward V", "Henry VIII"}, false, "history");
Question history4 = new Question("Who led Mongolia in establishing one of the largest land empires in the world?", new String[]{"Toghrul Khan", "Ogedei Khan", "Guyuk Khan", "Genghis Khan"}, false, "history");
Question history5 = new Question("Which country unofficially assisted the U.S. from the American Revolution up to WWI?", new String[]{"France", "Great Britain", "Tripoli", "Russia"}, false, "history");
Question history6 = new Question("In which civilization did cities originate first?", new String[]{"Egypt", "China", "Babylon", "Mesopotamia"}, false, "history");
Question history7 = new Question("Which country was the first in Europe to decriminalize homosexuality?", new String[]{"Spain", "Portugal", "Sweden", "France"}, false, "history");
Question history8 = new Question("A famous pacifistic, egalitarian, and often-persecuted Christian sect was", new String[]{"the Catholics.", "the Methodists.", "the Mormons.", "the Quakers."}, false, "history");
Question history9 = new Question("The major philosophical movement in the early 20th century was", new String[]{"Postmodernism.", "Scholasticism.", "Empiricism.", "Existentialism."}, false, "history");
Question history10 = new Question("Who wrote the 95 Theses?", new String[]{"The author was anonymous.", "Voltaire", "Confucius", "Martin Luther"}, false, "history");
Question history11 = new Question("Napolean was finally defeated at the battle of", new String[]{"Paris", "Borodino", "Dresden", "Waterloo"}, false, "history");
Question history12 = new Question("Who led the Bolshevik Revolution in Russia?", new String[]{"Catherine the Great", "Joseph Stalin", "Leon Trotsky", "Vladimir Lenin"}, false, "history");
Question history13 = new Question("Over what religious group did the Babylonians rule?", new String[]{"Christian", "Muslim", "Zoroastrian", "Jewish"}, false, "history");
Question history14 = new Question("Universities first appeared in what time period?", new String[]{"The Renaissance", "The Age of Enlightenment", "The Classical Era", "The Medieval Era"}, false, "history");
Question history15 = new Question("Which Mesoamerican civilization was known for regularly sacrificing people to make the sun rise?", new String[]{"The Maya", "The Inca", "The Choctaws", "The Aztecs"}, false, "history");
Question history16 = new Question("The Aroostook War resulted in which of the following?", new String[]{"The Aroostook tribes lost all of their land.", "The U.S. and Canada placed their border at the 49th parallel.", "Oregon became a jointly occupied area.", "Northern Maine was divided between British Canada and the U.S."}, false, "history");
Question history17 = new Question("Which war gave the U.S. the territory from Texas to California?", new String[]{"The Indian-American War", "The Great North American War", "The War of 1812", "The Mexican-American War"}, false, "history");
Question history18 = new Question("Around which river did Ancient Egyptian life revolve?", new String[]{"The Danube", "The Tiber", "The Tigris", "The Nile"}, false, "history");
Question history19 = new Question("The keystone Taoist piece Tao Te Ching is attributed to which of the following?", new String[]{"", "", "", ""}, false, "history");

Question math3 = new Question("5x^2 = 30. What is x?", new String[] {"36", "-sqrt(6)", "sqrt(6)", "+-sqrt(6)"}, false, "math");
Question math4 =  new Question("Simplify: 8x/sqrt(7)", new String[] {"8x", "8x*sqrt(7)", "x", "(8x*sqrt(7))/7"}, false, "math");
Question math5 = new Question("What is the value of sin(x)^2 + cos(x)^2 for all values of x?", new String[] {"0", "-pi/2", "pi/2", "1"}, false, "math");
Question math6 = new Question("The graph of ln(x+1) will cross the x-axis at what value of x?", new String[] {"1", "-1", "e", "0"}, false, "math");
Question math7 = new Question("What is Euler's Theorem?", new String[] {"f(x) * g(x) = f(g(x))", "tan(x)^2 + 1 = sec(x)^2", "sin(2u) = 2sin(u)cos(u)", "e^(pi*i) + 1 = 0"}, false, "math");
Question math8 = new Question("Where will the graph of 2^x - 1 cross the y-axis?", new String[] {"y=1", "y=-1", "It won't cross the y-axis.", "y=0"}, false, "math");
Question math9 = new Question("What is the value of e?", new String[] {"3.1416", "sqrt(-1)", "6.529 x 10^7", "2.7183"}, false, "math");
Question math10 = new Question("What is the formula for finding the area of a triangle?", new String[] {"bh", "pi*bh", "sin(A) * bh", "(1/2)bh"}, false, "math");
Question math11 = new Question("Factor x^2 - 2x - 24.", new String[] {"(x-12)(x+2)", "x(x-4)", "(x-2)(x+24)", "(x-6)(x+4)"}, false, "math");
Question math12 = new Question("Solve the system of equations: x + 2y = 9; 3x - 4y = -33", new String[] {"x=3, y=6", "x=-3, y=-6", "x=3, y=-6", "x=-3, y=6"}, false, "math");
Question math13 = new Question("What is the complex conjugate of 2 + 3i?", new String[] {"2 + 3i", "(2 + 3i)^2", "1/(2+3i)", "2 - 3i"}, false, "math");
Question math14 = new Question("What is 3^-3?", new String[] {"27", "-27", "-1/27", "1/27"}, false, "math");
Question math15 = new Question("What is 3^(1/3)?", new String[] {"The cube root of 3.", "1/27", "-1/27", "27"}, false, "math");
Question math16 = new Question("Condense the following: 5log(x) + 2log(y)", new String[] {"7log(x+y)", "It cannot be condensed.", "10log(x*y)", "log(x^5 * y^2"}, false, "math");
Question math17 = new Question("Is f(x) = 1/x differentiable?", new String[] {"No.", "Only for values of x above 0.", "Only for non-real values of x.", "Yes, except when x is 0."}, false, "math");
Question math18 = new Question("Find f'(2) given that f(x) = 5 - x^3.", new String[] {"12", "2", "-2", "-12"}, false, "math");
Question math19 = new Question("What is the median of the following data set? 1, 101.3, 89, 9, 5, 22, 101, 12", new String[] {"12", "22", "89", "17"}, false, "math");
Question math20 = new Question("Solve for x: sqrt(x) + 20 = 31", new String[] {"11^x", "11", "sqrt(11)", "121"}, false, "math");

Question science3 = new Question("What is the first group on the periodic table called?", new String[] {"Alkaline Group", "Noble Gases", "Halogens", "Alkali Metal Group"}, false, "science");
Question science4 = new Question("What is the formula for kinetic energy?", new String[] {"m^v", "(1/2)v*m^3", "m*v", "(1/2)mv^2"}, false, "science");
Question science5 = new Question("Who directed the gold foil experiment?", new String[] {"Werner Heisenberg", "John Dalton", "J. J. Thomson", "Ernest Rutherford"}, false, "science");
Question science6 = new Question("What is the speed of light in a vacuum?", new String[] {"186,282 km/sec", "186,282 miles/hour", "186,282 km/hour", "186,282 miles/sec"}, false, "science");
Question science7 = new Question("Which of the following is the largest known star?", new String[] {"VY Canis Majoris", "Betelgeuse", "VV Cephei A", "NML Cygni"}, false, "science");
Question science8 = new Question("Which of these did Einstein discover/formulate?", new String[] {"The Uncertainty Principle", "The Black Hole concept", "The fact that the universe is expanding.", "The Theory of Critical Opalescence"}, false, "science");
Question science9 = new Question("Which of the following is not part of cell theory?", new String[] {"All living organisms are made of cells.", "Cells are the basic units of life.", "Cells arise from pre-existing cells.", "All cells undergo mitosis or meiosis to multiply."}, false, "science");
Question science10 = new Question("A carboxyl group is a functional group consisting of", new String[] {"Carbon and oxygen", "Nitrogen and hydroxyl", "Nitrogen, carbon, oxygen, and hydroxyl", "Carbon, oxygen, and hydroxyl"}, false, "science");
Question science11 = new Question("What is the electron configuration of Copper?", new String[] {"1s2 2s2 2p6", "1s2 2s2 2p6 3s1", "1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p3", "1s2 2s2 2p6 3s2 3p6 3d9 4s2"}, false, "science");
Question science12 = new Question("Water is a(n) ________.", new String[] {"non-polar covalent molecule", "ionic compound", "supercritical fluid", "polar covalent molecule"}, false, "science");
Question science13 = new Question("What organelle appears in plant cells but not animal cells?", new String[] {"Endoplasmic Reticulum", "Golgi Body", "Ribosomes", "Central Vacuole"}, false, "science");
Question science14 = new Question("When water \"sticks\" to other materials, it is called", new String[] {"cohesion.", "capillary action.", "fusion.", "adhesion."}, false, "science");
Question science15 = new Question("Uranium is a part of which part of the periodic table?", new String[] {"Lanthanides", "Transition Metals", "Synthetic Elements", "Actinides"}, false, "science");
Question science16 = new Question("As one goes down a hill, one's potential energy _______.", new String[] {"increases", "remains constant", "is converted into heat", "decreases"}, false, "science");
Question science17 = new Question("Enzymes are simply organic ______.", new String[] {"acids", "filters", "immune system constituents", "catalysts"}, false, "science");
Question science18 = new Question("Approximately how old is the earth?", new String[] {"6,000 years", "13.4 billion years", "64 million years", "4.6 billion years"}, false, "science");
Question science19 = new Question("What happens to the gravity between two objects as they become more distant from each other?", new String[] {"It increases.", "It does not change.", "It depends on the size of the objects.", "It decreases."}, false, "science");
Question[] allQuestions = {history0, history1, history2, math0, math1, math2, science0, science1, science2, fl0, fl1, fl2};

int score;


@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();


    String[] subject_chosen = intent.getStringArrayExtra("SUBJECT");
    SubjectSelected= subject_chosen;
    for (String t : subject_chosen) {
        subjectExhausted.put(t, false);
    }
    setContentView(com.ultimanaire.R.layout.activity_game); 
    chooseSubject();
    chooseQuestion();
}

public void onSubmit() {
    TextView questiont = new TextView(this);
    questiont = (TextView)findViewById(R.id.question);
    String checkedQuestion = "";

    for (CheckBox o : cbc) {
        if (o.isChecked()) {
            checkedQuestion = o.getText().toString();           }
    }

    for (Question b: allQuestions) {
        if(questiont.getText() == b.question) {
            if (b.answers[3].equals(checkedQuestion)) {
                score = score + 100;
                chooseSubject();
                chooseQuestion();
            }
            else {

                Intent intent = new Intent(this, EndGame.class);
                intent.putExtra("SCORE", score);
                startActivity(intent);
            }
        }


    }
}




public void chooseQuestion() {

    TextView subjectCheck = new TextView(this);
    subjectCheck = (TextView)findViewById(R.id.subject);
    String currentSubject = (String) subjectCheck.getText();

    Random gen1 = new Random();
    Question randomQuestion = allQuestions[gen1.nextInt(allQuestions.length)];
    if (randomQuestion.subject.equals(currentSubject)) {
        TextView question = new TextView(this);
        question = (TextView)findViewById(R.id.question);
        question.setText(randomQuestion.question);
        int[] answer = new int[4];
        int[] used = new int[4];
        for (int i = 0; i < 4;){
            int rand = gen1.nextInt(4);
            boolean alreadyUsed = false;
            for (int j: used) {
                if (rand == j) {
                    alreadyUsed = true;
                }
            }
            if (alreadyUsed == false){
                answer[i] = rand;
                i++;
            }
        }

        CheckBox answerbox = new CheckBox(this);
        answerbox = (CheckBox)findViewById(R.id.answer_1);
        answerbox.setText(randomQuestion.answers[answer[0]]);

        CheckBox answerbox1 = new CheckBox(this);
        answerbox1 = (CheckBox)findViewById(R.id.answer_2);
        answerbox1.setText(randomQuestion.answers[answer[1]]);

        CheckBox answerbox2 = new CheckBox(this);
        answerbox2 = (CheckBox)findViewById(R.id.answer_3);
        answerbox2.setText(randomQuestion.answers[answer[2]]);

        CheckBox answerbox3 = new CheckBox(this);
        answerbox3 = (CheckBox)findViewById(R.id.answer_4);
        answerbox3.setText(randomQuestion.answers[answer[3]]);
    }
}

public void chooseSubject() {

    Random generator = new Random();
    Object[] keys = SubjectSelected;
    String randomValue = (String) keys[generator.nextInt(keys.length)];
    String newSubject = randomValue;
    TextView r = new TextView(this);
    r=(TextView)findViewById(R.id.subject);
    r.setText(newSubject);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_game, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

0 个答案:

没有答案