Example usage for android.widget LinearLayout getChildCount

List of usage examples for android.widget LinearLayout getChildCount

Introduction

In this page you can find the example usage for android.widget LinearLayout getChildCount.

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java

private boolean showPickupsInfo(final LocalDate date) {
    final List<PickupInfo> from = DB.pickups().findByFrom(date, true);
    if (!from.isEmpty()) {

        TextView title = ((TextView) bottomSheet.findViewById(R.id.bottom_sheet_title));

        LayoutInflater i = getLayoutInflater();
        LinearLayout list = (LinearLayout) findViewById(R.id.pickup_list);
        list.removeAllViews();//from  w w w .ja  v  a2  s  .c o m
        for (final PickupInfo p : from) {

            Medicine m = DB.medicines().findById(p.medicine().getId());
            Patient pat = DB.patients().findById(m.patient().id());

            if (selectedPatientIdx == 0 || pat.id() == selectedPatientId) {

                View v = i.inflate(R.layout.calendar_pickup_list_item, null);
                TextView tv1 = ((TextView) v.findViewById(R.id.textView));
                TextView tv2 = ((TextView) v.findViewById(R.id.textView2));
                ImageView avatar = ((ImageView) v.findViewById(R.id.avatar));
                String interval = getResources().getString(R.string.pickup_interval, p.to().toString(df));

                if (p.taken()) {
                    interval += " ";
                    tv1.setAlpha(0.5f);
                } else {
                    tv1.setAlpha(1f);
                    tv2.setAlpha(1f);
                }

                tv1.setText(p.medicine().name());
                tv2.setText(interval);
                avatar.setImageResource(AvatarMgr.res(pat.avatar()));

                tv1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        p.taken(!p.taken());
                        DB.pickups().save(p);
                        showPickupsInfo(date);
                    }
                });
                list.addView(v);
            }
        }
        nestedScrollView.scrollBy(0, bottomSheet.getHeight());
        showBottomSheet();
        int total = list.getChildCount();
        title.setText(
                total + " " + getResources().getString(R.string.title_pickups_bottom_sheet, date.toString(df)));
        appBarLayout.setExpanded(false, true);
        return true;
    }
    return false;
}

From source file:com.example.drugsformarinemammals.Dose_Information.java

public void additionalInformationInterface(String option, String drug_name, String group_name,
        ArrayList<String> notesIndex, ArrayList<Article_Reference> referencesIndex) {

    LinearLayout borderLayout = createBorderLayout();
    ArrayList<String> notes = new ArrayList<String>();
    if (option.equals("GENERAL NOTES")) {
        SQLiteDatabase db = helper.open();
        if (db != null) {
            notes = helper.read_general_notes(drug_name, group_name);
            helper.close();/* w w  w  .  j a v  a  2  s  .  c  om*/
        }
    } else if (option.equals("SPECIFIC NOTES")) {
        notes = notesIndex;
    }

    if (((option.equals("GENERAL NOTES") || option.equals("SPECIFIC NOTES")) && notes.size() > 0)
            || (option.equals("REFERENCES") && referencesIndex.size() > 0)) {
        TextView titleTextView = createTitleTextView();
        titleTextView.setText(option);
        LinearLayout.LayoutParams params = createTextViewParams("Title TextView");
        layoutDose.addView(titleTextView, layoutDose.getChildCount(), params);
        if (option.equals("GENERAL NOTES") || option.equals("SPECIFIC NOTES")) {
            for (int i = 0; i < notes.size(); i++) {
                TextView informationTextView = createInformationTextView();
                if (option.equals("GENERAL NOTES"))
                    informationTextView.setText("   " + notes.get(i));
                else
                    informationTextView.setText("(" + (i + 1) + ")   " + notesIndex.get(i));
                LinearLayout.LayoutParams informationParams = createTextViewParams("Information TextView");
                borderLayout.addView(informationTextView, borderLayout.getChildCount(), informationParams);
            }
        } else {
            for (int i = 0; i < referencesIndex.size(); i++) {
                TextView informationTextView = createInformationTextView();
                informationTextView.setText(
                        "(" + referencesIndex.get(i).getIndex() + ")   " + referencesIndex.get(i).getArticle());
                LinearLayout.LayoutParams informationParams = createTextViewParams("Information TextView");
                borderLayout.addView(informationTextView, borderLayout.getChildCount(), informationParams);
            }
        }
    }

    layoutDose.addView(borderLayout, layoutDose.getChildCount());

}

From source file:com.httrack.android.HTTrackActivity.java

private void removeLinesFromLayout(final LinearLayout layout, final int fromPosition) {
    if (fromPosition < layout.getChildCount()) {
        layout.removeViews(fromPosition, layout.getChildCount() - fromPosition);
    }//from   ww  w.  j  ava 2 s.c  om
}

From source file:foam.starwisp.StarwispBuilder.java

public String WalkDraggable(StarwispActivity ctx, String name, String ctxname, int id) {
    View v = ctx.findViewById(id);
    Class c = v.getClass();/*from ww w  . java  2  s .com*/
    String ret = "";
    if (c == LinearLayout.class) {
        LinearLayout l = (LinearLayout) v;
        String result = m_Scheme.eval("(run-draggable-callback \"" + ctxname + "\" " + id + " '())") + " ";
        try {
            JSONArray arr = new JSONArray(result);

            int is_atom = arr.getInt(0);
            if (is_atom == 0)
                ret += "(";

            // a number?
            if (is_atom == 2)
                ret += arr.getString(1) + " ";
            else
                ret += JSONToScheme(arr.getString(1)) + " ";

            //Log.i("starwisp","post conv "+ret);

            for (int i = 0; i < l.getChildCount(); i++) {
                View cv = l.getChildAt(i);
                Class cc = cv.getClass();
                if (cc == LinearLayout.class) {
                    ret += WalkDraggable(ctx, name, ctxname, cv.getId());
                }
            }
            if (is_atom == 0)
                ret += ")";
        } catch (JSONException e) {
            Log.e("starwisp", "Error parsing draggable code " + e.toString());
            Log.e("starwisp", "Code is: " + ret);
            return "";
        }
    }
    return ret;
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }/* ww  w .  j  a v a 2 s  .  c o m*/
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:reportsas.com.formulapp.Formulario.java

public int ObtenerRespuesta(LinearLayout contenedor, Pregunta Pregunta,
        ArrayList<PreguntaRespuesta> respuestaList) {
    PreguntaRespuesta result = new PreguntaRespuesta();
    int numRespuesta = 0;
    result.setIdPregunta(Pregunta.getIdPregunta());
    EditText resp;// w ww .  j  a  v a 2 s  .co m
    TextView selectio;
    switch (Pregunta.getTipoPregunta()) {
    case 1:
        resp = (EditText) contenedor.findViewById(R.id.edtTexto);
        result.setItem(1);
        result.setRespuesta(resp.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 2:
        resp = (EditText) contenedor.findViewById(R.id.mtxtEdit);
        result.setItem(1);
        result.setRespuesta(resp.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 3:
        selectio = (TextView) contenedor.findViewById(R.id.respuestaGruop);
        result.setItem(1);
        result.setRespuesta(selectio.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 4:

        String resp_opcio = "";
        for (int j = 0; j < contenedor.getChildCount(); j++) {
            View child = contenedor.getChildAt(j);
            if (child instanceof CheckBox) {
                CheckBox hijo = (CheckBox) child;
                if (hijo.isChecked()) {
                    if (resp_opcio.length() == 0) {
                        if (Pregunta.isOpcionEditble(hijo.getText().toString())) {
                            EditText otrosR = (EditText) contenedor.findViewById(R.id.edtTexto);
                            resp_opcio = otrosR.getText().toString();
                        } else {
                            resp_opcio = hijo.getText().toString();
                        }
                    } else {
                        if (Pregunta.isOpcionEditble(hijo.getText().toString())) {
                            EditText otrosR = (EditText) contenedor.findViewById(R.id.edtTexto);
                            resp_opcio += " , " + otrosR.getText().toString() + " ";
                        } else {
                            resp_opcio = resp_opcio + " , " + hijo.getText() + " ";
                        }

                    }
                }
            }

        }
        result.setItem(1);
        result.setRespuesta(resp_opcio);
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 5:
        selectio = (TextView) contenedor.findViewById(R.id.seleEscala);
        result.setItem(1);
        result.setRespuesta(selectio.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 6:
        Spinner lista = (Spinner) contenedor.findViewById(R.id.opcionesListado);
        result.setItem(1);
        result.setRespuesta(lista.getSelectedItem().toString() + "");
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 7:
        TableLayout tabla = (TableLayout) contenedor.findViewById(R.id.tablaOpciones);
        for (int i = 0; i < tabla.getChildCount(); i++) {
            TableRow registro = (TableRow) tabla.getChildAt(i);
            TextView etiq = (TextView) registro.findViewById(R.id.textoRow);
            RadioGroup selector = (RadioGroup) registro.findViewById(R.id.valoresRow);
            PreguntaRespuesta itemA = new PreguntaRespuesta();
            itemA.setIdPregunta(Pregunta.getIdPregunta());
            itemA.setItem(i + 1);
            itemA.setRespuesta(etiq.getText().toString());
            if (selector.getCheckedRadioButtonId() > 0) {
                RadioButton rb = (RadioButton) selector.findViewById(selector.getCheckedRadioButtonId());
                itemA.setOpcion(rb.getText() + "");
            }

            respuestaList.add(itemA);
            numRespuesta++;
        }

        break;
    case 8:
        DatePicker dp = (DatePicker) contenedor.findViewById(R.id.Fecha_resutl);
        result.setItem(1);
        result.setRespuesta(dp.getYear() + "-" + dp.getMonth() + "-" + dp.getDayOfMonth());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 9:
        TimePicker tp = (TimePicker) contenedor.findViewById(R.id.hora_result);
        result.setItem(1);
        result.setRespuesta(tp.getCurrentHour() + ":" + tp.getCurrentMinute());
        respuestaList.add(result);
        numRespuesta = 1;
        break;

    default:
        result.setItem(1);
        result.setRespuesta("Proceso");
        break;

    }

    return numRespuesta;

}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public void grabsamcounts() {

    int[] samcount = new int[view.maxelcs];
    for (int h = 0; h < samcount.length; h++) {
        samcount[h] = 0;//from w w w .  j  a  v a 2  s. co  m
    }

    int rownum = 0;

    try {
        View firstview;
        TableRow tablerow;
        TableLayout tablelayout;
        LinearLayout linearlayout;

        firstview = Tabs1.mcrentries[Tabs1.METERINGLIST][rownum][u.cellx("B1")];
        tablerow = ((TableRow) firstview.getParent());
        tablelayout = ((TableLayout) tablerow.getParent());
        linearlayout = (LinearLayout) tablelayout.getParent();

        Log.d("tablelayoutchild count", u.s(linearlayout.getChildCount()));
        for (int k = 0; k < linearlayout.getChildCount(); k++) {

            int elcnum = u.i(Tabs1.mcrentries[Tabs1.METERINGLIST][k][u.cellx("B1")].getText().toString());

            for (int y = 0; y < view.i; y++) {
                if ((view.ITEMtype[y] == view.TYPE_ELC) && view.ELCdisplaynumber[y] == elcnum) {
                    samcount[elcnum]++;
                }
            }
        }
        for (int y = 0; y < view.i; y++) {
            if ((view.ITEMtype[y] == view.TYPE_ELC)) {
                view.ITEMsamscount[y] = samcount[view.ELCdisplaynumber[y]];
            }
        }
    } catch (Throwable e) {

    }
}

From source file:info.tellmetime.DaydreamService.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    setInteractive(true);//from  ww w.  ja  v  a 2  s . c  o  m

    setFullscreen(true);

    setContentView(R.layout.daydream);

    LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);

    SharedPreferences settings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    mHighlightColor = settings.getInt(TellmetimeActivity.HIGHLIGHT, Color.WHITE);
    mBacklightColor = settings.getInt(TellmetimeActivity.BACKLIGHT,
            getResources().getColor(R.color.backlight_light));
    mMinutesSize = settings.getInt(TellmetimeActivity.MINUTES_SIZE, 36);
    isNightMode = settings.getBoolean(TellmetimeActivity.NIGHTMODE, false);

    setScreenBright(!isNightMode);
    findViewById(R.id.overlay).setBackgroundColor(
            getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent));

    RelativeLayout mSurface = (RelativeLayout) findViewById(R.id.surface);
    mSurface.setBackgroundColor(
            settings.getInt(TellmetimeActivity.BACKGROUND, getResources().getColor(R.color.background)));
    switch (settings.getInt(TellmetimeActivity.BACKGROUND_MODE, TellmetimeActivity.MODE_BACKGROUND_SOLID)) {
    case TellmetimeActivity.MODE_BACKGROUND_WALLPAPER:
        ((ImageView) findViewById(R.id.background_image))
                .setImageDrawable(WallpaperManager.getInstance(this).getDrawable());
        break;

    case TellmetimeActivity.MODE_BACKGROUND_IMAGE:
        try {
            ((ImageView) findViewById(R.id.background_image)).setImageBitmap(BitmapFactory.decodeStream(
                    new FileInputStream(new File(getFilesDir(), TellmetimeActivity.IMAGE_FILE_NAME))));
        } catch (Exception ignored) {
            // Image is not set, set background color loaded from setting is visible.
        }

        break;
    }

    mShorterEdge = Math.min(getResources().getDisplayMetrics().widthPixels,
            getResources().getDisplayMetrics().heightPixels);
    mDensity = getResources().getDisplayMetrics().density;

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    lp.width = mShorterEdge;
    mClock.setLayoutParams(lp);

    Typeface mTypeface = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");
    final float mItemSize = mShorterEdge / mClock.getChildCount();
    final int mRowMargin = (int) -(mItemSize / 2.2);

    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
        params.bottomMargin = mRowMargin;
        row.setLayoutParams(params);

        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);

            tv.setTypeface(mTypeface);
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize);
            tv.setTextColor(mBacklightColor);
            tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
        }
    }
    LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams();
    params.bottomMargin = 0;
    lastRow.setLayoutParams(params);

    TextView twenty = (TextView) findViewById(R.id.twenty);
    params = (LinearLayout.LayoutParams) twenty.getLayoutParams();
    params.leftMargin = 0;
    twenty.setLayoutParams(params);

    inflateMinutesIndicators();
}

From source file:com.google.android.gcm.demo.ui.TopicsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        // Check if at least a topic is subscribed for this sender
        int subscribedTopics = 0;
        for (Boolean subscribed : sender.topics.values()) {
            if (subscribed) {
                subscribedTopics++;//from   w  w w .  java 2 s.  co m
            }
        }
        if (subscribedTopics > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Map.Entry<String, Boolean> topic : sender.topics.entrySet()) {
                if (topic.getValue()) {
                    LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                            .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                    Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                    icon.setImageResource(R.drawable.bigtop_updates_grey600);
                    label.setText(topic.getKey());
                    button.setText(R.string.topics_unsubscribe);
                    button.setTag(R.id.tag_action, ACTION_UNSUBSCRIBE);
                    button.setTag(R.id.tag_senderid, sender.senderId);
                    button.setTag(R.id.tag_topic, topic.getKey());
                    button.setOnClickListener(this);
                    row.setPadding((int) (16 * density), 0, 0, 0);
                    sendersList.addView(row);
                }
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.topics_no_topic_subscribed));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.topics_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.httrack.android.HTTrackActivity.java

private void setProgressLinesInternal(final String[] lines) {
    // Get line divider position of the bottom coordinate
    final View lineDivider = findViewById(R.id.buttonStop);
    if (lineDivider == null) {
        return;/*from  w  w w.  j  a  v a 2 s.  c  om*/
    }
    final int[] textPosition = new int[2];
    final int[] linePosition = new int[2];
    lineDivider.getLocationInWindow(linePosition);
    final int lineYTopPosition = linePosition[1];

    // Explode lines
    final LinearLayout layout = LinearLayout.class.cast(findViewById(R.id.layout));

    // Remove any additional lines
    removeLinesFromLayout(layout, lines.length);

    // Add lines while we can
    final int currSize = layout.getChildCount();
    for (int i = 0; i < lines.length; i++) {
        // Fetch or create next layout line.
        final TextView text = i < currSize ? TextView.class.cast(layout.getChildAt(i))
                : addEmptyLineToLayout(layout);

        // Stop adding lines if overlapping to the end of the screen
        text.getLocationInWindow(textPosition);
        final int height = text.getHeight();
        final int textYBottomPosition = textPosition[1] + height;
        if (textYBottomPosition >= lineYTopPosition) {
            // Then cut everything remaining
            removeLinesFromLayout(layout, i);

            // Stop here
            break;
        }

        // Set text (html-formatted) for this line
        final String line = lines[i].trim();
        if (line.length() != 0) {
            text.setText(Html.fromHtml(line));
        } else {
            // Otherwise Android 3.0 does not insert any blank line
            text.setText(Html.fromHtml("&nbsp;"));
        }
    }
}