Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* This file is part of SlumDroid <https://github.com/slumdroid/slumdroid>.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License <http://www.gnu.org/licenses/gpl-3.0.txt>
 * for more details.
 * 
 * Copyright (C) 2012-2016 Gennaro Imparato
 */

import android.view.View;

import android.widget.EditText;

import android.widget.RadioGroup;

import android.widget.TextView;

public class Main {
    /**
     * Detect name.
     *
     * @param view the view
     * @return the string
     */
    public static String detectName(View view) {
        String name = new String();
        if (view instanceof TextView) {
            name = ((TextView) view).getText().toString();
            if (view instanceof EditText) {
                CharSequence hint = ((EditText) view).getHint();
                name = (hint == null) ? new String() : hint.toString();
            }
            return name;
        }
        if (view instanceof RadioGroup) {
            RadioGroup group = (RadioGroup) view;
            int max = group.getChildCount();
            String text = new String();
            for (int item = 0; item < max; item++) {
                View child = group.getChildAt(item);
                text = detectName(child);
                if (!text.equals("")) {
                    name = text;
                    break;
                }
            }
        }
        return name;
    }
}