Example usage for android.widget TextView getParent

List of usage examples for android.widget TextView getParent

Introduction

In this page you can find the example usage for android.widget TextView getParent.

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:org.travey.travey.QuestionActivity.java

public void prepareQuestions() {
    //add items to spinner
    TextView textView0 = (TextView) findViewById(R.id.textview0);
    TextView textView1 = (TextView) findViewById(R.id.textview1);
    Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner1.setOnItemSelectedListener(this);
    TextView textView2 = (TextView) findViewById(R.id.textview2);
    Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
    spinner2.setOnItemSelectedListener(this);
    TextView textView3 = (TextView) findViewById(R.id.textview3);
    Spinner spinner3 = (Spinner) findViewById(R.id.spinner3);
    spinner3.setOnItemSelectedListener(this);
    TextView textView4 = (TextView) findViewById(R.id.textview4);
    Spinner spinner4 = (Spinner) findViewById(R.id.spinner4);
    spinner4.setOnItemSelectedListener(this);
    TextView textView5 = (TextView) findViewById(R.id.textview5);
    Spinner spinner5 = (Spinner) findViewById(R.id.spinner5);
    spinner5.setOnItemSelectedListener(this);
    TextView textView6 = (TextView) findViewById(R.id.textview6);
    Spinner spinner6 = (Spinner) findViewById(R.id.spinner6);
    spinner6.setOnItemSelectedListener(this);
    TextView textView7 = (TextView) findViewById(R.id.textview7);
    Spinner spinner7 = (Spinner) findViewById(R.id.spinner7);
    spinner7.setOnItemSelectedListener(this);
    TextView textView8 = (TextView) findViewById(R.id.textview8);
    Spinner spinner8 = (Spinner) findViewById(R.id.spinner8);
    spinner8.setOnItemSelectedListener(this);
    Intent i = getIntent();//  w w  w  .  ja v a2s.  c  o m
    String tripText = "This " + metersToPhrase(Integer.parseInt(i.getStringExtra("distance"))) + " trip, took "
            + roundDownTo5(((Long.parseLong(i.getStringExtra("finishTime"))
                    - Long.parseLong(i.getStringExtra("startTime"))) / (1000 * 60) % 60))
            + " minutes, and ended at "
            + dateToQuarters(new Date(Long.parseLong(i.getStringExtra("finishTime")))) + " on "
            + simpleDateFormat.format(new Date(Long.parseLong(i.getStringExtra("finishTime")))) + ".";
    textView0.setText(tripText);
    Log.i("**************", "number of questions:" + NUMBER_QUESTIONS);
    if (NUMBER_QUESTIONS >= 1) { //Q1
        textView1.setText(R.string.survey_question_1);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_1_choices, R.layout.my_spinner);
        spinner1.setAdapter(adapter);
    } else {
        textView1.setVisibility(View.GONE);
        ((ViewManager) textView1.getParent()).removeView(textView1);
        spinner1.setVisibility(View.GONE);
        ((ViewManager) spinner1.getParent()).removeView(spinner1);
    }
    if (NUMBER_QUESTIONS >= 2) { //Q2
        textView2.setText(R.string.survey_question_2);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_2_choices, R.layout.my_spinner);
        spinner2.setAdapter(adapter);
    } else {
        textView2.setVisibility(View.GONE);
        ((ViewManager) textView2.getParent()).removeView(textView2);
        spinner2.setVisibility(View.GONE);
        ((ViewManager) spinner2.getParent()).removeView(spinner2);
    }
    if (NUMBER_QUESTIONS >= 3) { //Q3
        textView3.setText(R.string.survey_question_3);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_3_choices, R.layout.my_spinner);
        spinner3.setAdapter(adapter);
    } else {
        textView3.setVisibility(View.GONE);
        ((ViewManager) textView3.getParent()).removeView(textView3);
        spinner3.setVisibility(View.GONE);
        ((ViewManager) spinner3.getParent()).removeView(spinner3);
    }
    if (NUMBER_QUESTIONS >= 4) { //Q4
        textView4.setText(R.string.survey_question_4);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_4_choices, R.layout.my_spinner);
        spinner4.setAdapter(adapter);
    } else {
        textView4.setVisibility(View.GONE);
        ((ViewManager) textView4.getParent()).removeView(textView4);
        spinner4.setVisibility(View.GONE);
        ((ViewManager) spinner4.getParent()).removeView(spinner4);
    }
    if (NUMBER_QUESTIONS >= 5) { //Q5
        textView5.setText(R.string.survey_question_5);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_5_choices, R.layout.my_spinner);
        spinner5.setAdapter(adapter);
    } else {
        textView5.setVisibility(View.GONE);
        ((ViewManager) textView5.getParent()).removeView(textView5);
        spinner5.setVisibility(View.GONE);
        ((ViewManager) spinner5.getParent()).removeView(spinner5);
    }
    if (NUMBER_QUESTIONS >= 6) { //Q6
        textView6.setText(R.string.survey_question_6);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_6_choices, R.layout.my_spinner);
        spinner6.setAdapter(adapter);
    } else {
        textView6.setVisibility(View.GONE);
        ((ViewManager) textView6.getParent()).removeView(textView6);
        spinner6.setVisibility(View.GONE);
        ((ViewManager) spinner6.getParent()).removeView(spinner6);
    }
    if (NUMBER_QUESTIONS >= 7) { //Q7
        textView7.setText(R.string.survey_question_7);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_7_choices, R.layout.my_spinner);
        spinner7.setAdapter(adapter);
    } else {
        textView7.setVisibility(View.GONE);
        ((ViewManager) textView7.getParent()).removeView(textView7);
        spinner7.setVisibility(View.GONE);
        ((ViewManager) spinner7.getParent()).removeView(spinner7);
    }
    if (NUMBER_QUESTIONS >= 8) { //Q8
        textView8.setText(R.string.survey_question_8);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.survey_question_8_choices, R.layout.my_spinner);
        spinner8.setAdapter(adapter);
    } else {
        textView8.setVisibility(View.GONE);
        ((ViewManager) textView8.getParent()).removeView(textView8);
        spinner8.setVisibility(View.GONE);
        ((ViewManager) spinner8.getParent()).removeView(spinner8);
    }
}

From source file:com.samknows.measurement.activity.SamKnowsTestViewerActivity.java

/** Called when the activity is first created. */
@Override//  w  ww  . j  av  a  2s  .  c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    cxt = this;

    Bundle b = getIntent().getExtras();
    int testID = -1;

    if (b != null) {
        testID = b.getInt("testID");
    }

    storage = CachingStorage.getInstance();
    config = storage.loadScheduleConfig();
    if (config == null) {
        config = new ScheduleConfig();
    }
    testList = config.manual_tests;
    array_spinner = new String[testList.size() + 1];
    array_spinner_int = new int[testList.size() + 1];

    this.setTitle(R.string.running_test);

    // choose which test to run
    setContentView(R.layout.individual_stat_test);

    Util.initializeFonts(this);
    Util.overrideFonts(this, findViewById(android.R.id.content));
    try {

        handler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                TextView tv = null;

                JSONObject message_json;
                message_json = (JSONObject) msg.obj;
                String value;
                int success;
                int testname;
                int status_complete;
                int metric;

                try {

                    String type = message_json.getString(TestResult.JSON_TYPE_ID);

                    if (type == "completed") {

                        result = 1;
                        SamKnowsTestViewerActivity.this.finish();
                        overridePendingTransition(0, 0);
                    }

                    if (type == "test") {
                        testname = message_json.getInt(TestResult.JSON_TESTNUMBER);
                        status_complete = message_json.getInt(TestResult.JSON_STATUS_COMPLETE);
                        value = message_json.getString(TestResult.JSON_HRRESULT);
                        if (status_complete == 100 && message_json.has(TestResult.JSON_SUCCESS)) {

                            success = message_json.getInt(TestResult.JSON_SUCCESS);
                            if (success == 0) {
                                value = getString(R.string.failed);
                            }
                        }

                        switch (testname) {
                        // active metrics
                        case TestResult.DOWNLOAD_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel1);
                            tv = (TextView) findViewById(R.id.download_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.download) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.UPLOAD_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel2);
                            tv = (TextView) findViewById(R.id.upload_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);

                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.upload) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.PACKETLOSS_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel3);
                            tv = (TextView) findViewById(R.id.packetloss_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.packet_loss) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.LATENCY_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel4);
                            tv = (TextView) findViewById(R.id.latency_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.latency) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;
                        case TestResult.JITTER_TEST_ID:
                            pw = (ProgressWheel) findViewById(R.id.ProgressWheel5);
                            tv = (TextView) findViewById(R.id.jitter_result);
                            pw.setProgress((int) (status_complete * 3.6));
                            pw.setContentDescription("Status " + status_complete + "%");
                            if (status_complete == 100) {
                                pw.setVisibility(View.GONE);
                                tv.setText(value);
                                tv.setContentDescription(getString(R.string.jitter) + " " + value);
                                tv.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                            } else {
                                pw.setVisibility(View.VISIBLE);
                                tv.setText("");
                            }
                            break;

                        }
                    }

                    if (type == "passivemetric") {
                        metric = message_json.getInt("metric");
                        value = message_json.getString("value");

                        switch (metric) {

                        // passive metrics
                        case 1:
                            tv = (TextView) findViewById(R.id.passivemetric1);
                            tv.setText(value);
                            break;

                        case 2:
                            tv = (TextView) findViewById(R.id.passivemetric2);
                            tv.setText(value);
                            break;

                        case 3:
                            tv = (TextView) findViewById(R.id.passivemetric3);
                            tv.setText(value);
                            break;

                        case 4:
                            tv = (TextView) findViewById(R.id.passivemetric4);
                            tv.setText(value);
                            break;

                        case 5:
                            tv = (TextView) findViewById(R.id.passivemetric5);
                            tv.setText(value);
                            break;

                        case 6:
                            tv = (TextView) findViewById(R.id.passivemetric6);
                            tv.setText(value);
                            break;

                        case 7:
                            tv = (TextView) findViewById(R.id.passivemetric7);
                            tv.setText(value);
                            break;

                        case 8:
                            tv = (TextView) findViewById(R.id.passivemetric8);
                            tv.setText(value);
                            break;

                        case 9:
                            tv = (TextView) findViewById(R.id.passivemetric9);
                            tv.setText(value);
                            break;

                        case 10:
                            tv = (TextView) findViewById(R.id.passivemetric10);
                            tv.setText(value);
                            break;

                        case 11:
                            tv = (TextView) findViewById(R.id.passivemetric11);
                            tv.setText(value);
                            break;
                        case 12:
                            tv = (TextView) findViewById(R.id.passivemetric12);
                            tv.setText(value);
                            break;
                        case 13:
                            tv = (TextView) findViewById(R.id.passivemetric13);
                            tv.setText(value);
                            break;
                        case 14:
                            tv = (TextView) findViewById(R.id.passivemetric14);
                            tv.setText(value);
                            break;
                        case 15:
                            tv = (TextView) findViewById(R.id.passivemetric15);
                            tv.setText(value);
                            break;
                        case 16:
                            tv = (TextView) findViewById(R.id.passivemetric16);
                            tv.setText(value);
                            break;
                        case 17:
                            tv = (TextView) findViewById(R.id.passivemetric17);
                            tv.setText(value);
                            break;
                        case 18:
                            tv = (TextView) findViewById(R.id.passivemetric18);
                            tv.setText(value);
                            break;
                        case 19:
                            tv = (TextView) findViewById(R.id.passivemetric19);
                            tv.setText(value);
                            break;
                        case 20:
                            tv = (TextView) findViewById(R.id.passivemetric20);
                            tv.setText(value);
                            break;
                        case 21:
                            tv = (TextView) findViewById(R.id.passivemetric21);
                            tv.setText(value);
                            break;
                        case 22:
                            tv = (TextView) findViewById(R.id.passivemetric22);
                            tv.setText(value);
                            break;
                        case 23:
                            tv = (TextView) findViewById(R.id.passivemetric23);
                            tv.setText(value);
                            break;
                        case 24:
                            tv = (TextView) findViewById(R.id.passivemetric24);
                            tv.setText(value);
                            break;
                        case 25:
                            tv = (TextView) findViewById(R.id.passivemetric25);
                            tv.setText(value);
                            break;
                        case 26:
                            tv = (TextView) findViewById(R.id.passivemetric26);
                            tv.setText(value);
                            break;
                        case 27:
                            tv = (TextView) findViewById(R.id.passivemetric27);
                            tv.setText(value);
                            break;
                        case 28:
                            tv = (TextView) findViewById(R.id.passivemetric28);
                            tv.setText(value);
                            break;
                        case 29:
                            tv = (TextView) findViewById(R.id.passivemetric29);
                            tv.setText(value);
                            break;
                        case 30:
                            tv = (TextView) findViewById(R.id.passivemetric30);
                            tv.setText(value);
                            break;
                        case 31:
                            tv = (TextView) findViewById(R.id.passivemetric31);
                            tv.setText(value);
                            break;
                        case 32:
                            tv = (TextView) findViewById(R.id.passivemetric32);
                            tv.setText(value);
                            break;
                        default:
                            //

                        }
                        if (!value.equals("") && tv != null) {

                            TableLayout tl1 = (TableLayout) findViewById(R.id.passive_metrics_status);
                            tl1.setVisibility(View.GONE);
                            TableLayout tl = (TableLayout) tv.getParent().getParent();
                            tl.setVisibility(View.VISIBLE);
                        }

                        if (value.equals("") && tv != null) {
                            TableLayout tl = (TableLayout) tv.getParent().getParent();
                            tl.setVisibility(View.GONE);
                        }

                    }

                } catch (JSONException e) {
                    Logger.e(this, e.getMessage());
                }
            }
        };

        launchTest(testID);
    } catch (Throwable t) {
        Logger.e(this, "handler or test failure", t);
    }
}