O
O
Oleksandr Shcherbak2019-06-11 15:33:57
Java
Oleksandr Shcherbak, 2019-06-11 15:33:57

How to properly insert a ListView into a Fragment?

Good afternoon. Help me to understand. It is necessary that the fragment has buttons and text (colored with indents), and the fragment itself can be shifted (Scroll). Now only text (colored with indents) is placed in the ScrollView, and when I add buttons there, it writes an error. I read that you need to use ListView instead of ScrollView, but then in the class I don’t know how to write the code correctly. Or tell me please, where to read?
5cff9f1698a29243707455.jpeg
java class

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.annotation.Nullable;
import android.widget.TextView;

public class Kafuzma1 extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_kafuzma1, container, false);

        TextView Molitvi = (TextView) rootView.findViewById(R.id.Molitvi);
        String text = "<font COLOR='RED'>\t\t\t\t\tПро те, яким чином слід співати Псалтир, дотримуючись розумної послідовності.</font> +
                "\t\tБлагословен Бог наш завжди, нині, і повсякчас, і на віки віків.<br />\t\t\t\t\tЯкщо мирянин, то промовляє зворушено:<br />" +
                "Молитвами святих отців наших, Господи Ісусе Христе Боже наш, помилуй нас. Амінь.<br />" +
    ..................................
                " ";
        Molitvi.setText(Html.fromHtml(text));
        return rootView;
    }
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getActivity().setTitle("Кафизма 1");
    }
}

snippet code part
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:padding="5sp"
    tools:context=".Kafuzma1">
..........
     <com.google.android.flexbox.FlexboxLayout
        android:id="@+id/Box"
        app:alignItems="center"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_below="@+id/butKf_2"
        android:layout_marginTop="10dp"
        app:flexWrap="wrap">
.......................
        <Button
            android:id="@+id/button7"
            style="@style/btn_Psalmu"
            android:text="7"
            android:textSize="16dp" />
        <Button
            android:id="@+id/button8"
            style="@style/btn_Psalmu"
            android:text="8"
            android:textSize="16dp" />
    </com.google.android.flexbox.FlexboxLayout>

    <ScrollView
        android:id="@+id/kafizma1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Box">
        <TextView
            android:id="@+id/Molitvi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp" />
    </ScrollView>
</RelativeLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2019-06-11
@shesa

ScrollView can only contain one nested element.
If you need more, take a LinearLayout and insert several elements into it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question