0
I have the following Fragment
:
public class ListaBimestresFragment extends Fragment {
public ListaBimestresFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_lista_bimestres, container, false);
return view;
}
}
I put him inside the OnClickListener
, thus:
public class FormularioDisciplina extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario_disciplina);
Button adicionarBimeste = findViewById(R.id.formulario_adicionar_bim);
adicionarBimeste.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction tx = fragmentManager.beginTransaction();
tx.replace(R.id.formulario_main, new ListaBimestresFragment());
tx.commit();
}
});
}
}
It turns out that by turning and clicking the button, it gives a warning:
I/Choreographer: Skipped 36 frames!
The application may be doing too much work on its main thread.
How can I fix this?
XML main:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:text="Preencha os campos abaixo:"
android:textColor="#000"/>
<EditText
android:id="@+id/formulario_materia"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="135dp"
android:hint="Matéria"
android:padding="10dp"/>
<EditText
android:id="@+id/formulario_professor"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="135dp"
android:hint="Professor"
android:padding="10dp"/>
<EditText
android:id="@+id/formulario_obs"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="135dp"
android:hint="Observações"
android:padding="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adicione seus bimestres"
android:textSize="19sp"
android:layout_marginTop="10dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+"
android:layout_marginTop="10dp"
android:id="@+id/formulario_adicionar_bim"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/insert_point"/>
XML Fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/adicionar_Layout"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<EditText
android:id="@+id/formulario_nota1"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:hint="Primeira nota"
android:inputType="textPersonName"
android:padding="10dp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="135dp" />
<EditText
android:id="@+id/formulario_nota2"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="0dp"
android:background="@drawable/rounded_edittext"
android:ems="10"
android:hint="Segunda nota"
android:inputType="textPersonName"
android:padding="10dp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="135dp" />
</RelativeLayout>
This message can appear when you have long processes and so the frames are ignored or because of the emulator, 36 frames is a small number, if it is more than 100, you would need to do something to avoid this. Take a look here: Processes and links Regarding creating a Fragment by clicking the button, you need to specify some error message that is happening. Also provide the xml of your main and your Fragment.
– Murillo Comino
@Murillocomino added their XML to the question. Regarding the error message, nothing appears when I click, only the message I put in the question when opening the Intent. Thanks in advance for replying!
– Matheus Alexander