Answer the question
In order to leave comments, you need to log in
How to solve the transfer of logic from activity to fragments?
The meaning of the problem is the following, how can I transfer the logic from activity to fragmtnts? When transferring Android studia swears at my shit code, help me solve the problem.
Activity code:
package com.example.user.dbv2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.GenericTypeIndicator;
import com.google.firebase.database.ValueEventListener;
import java.util.List;
public class Content_mainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private DatabaseReference myRef;
private List<String> drive;
private List<String> drive2;
private List<String> teor;
private List<String> teor2;
ListView ListUserDrive;
ListView ListUserDrive2;
ListView ListUserTeor;
ListView ListUserTeor2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content_main);
ListUserDrive = (ListView) findViewById(R.id.discr_for_tasks);
ListUserDrive2 = (ListView) findViewById(R.id.discr_for_tasks_test);
ListUserTeor = (ListView) findViewById(R.id.teor);
ListUserTeor2 = (ListView) findViewById(R.id.teor2);
myRef = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = mAuth.getInstance().getCurrentUser();
myRef.child(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
GenericTypeIndicator<List<String>> t = new GenericTypeIndicator<List<String>>() {};
GenericTypeIndicator<List<String>> t2 = new GenericTypeIndicator<List<String>>() {};
GenericTypeIndicator<List<String>> t3 = new GenericTypeIndicator<List<String>>() {};
GenericTypeIndicator<List<String>> t4 = new GenericTypeIndicator<List<String>>() {};
drive = dataSnapshot.child("Вождение").getValue(t);
drive2 = dataSnapshot.child("Вождение_Когда").getValue(t2);
teor = dataSnapshot.child("Теория").getValue(t3);
teor2 = dataSnapshot.child("Теория_Когда").getValue(t4);
updateUI();
updateUI2();
updateUI3();
updateUI4();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void updateUI() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, drive);
ListUserDrive.setAdapter(adapter);
}
private void updateUI2() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, drive2);
ListUserDrive2.setAdapter(adapter);
}
private void updateUI3() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, teor);
ListUserTeor.setAdapter(adapter);
}
private void updateUI4() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, teor2);
ListUserTeor2.setAdapter(adapter);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question