-2
My Recycler view does not appear on the screen if anyone can help I’m a beginner so I’m struggling, but I managed to do two other only that is keeping me awake :/ Thank you very much =]
MY ADAPTER
public class DiasAdapter extends RecyclerView.Adapter<DiasAdapter.MyViewHolder> {
ArrayList<Dia> dias;
Context context;
DiasListner diasListner;
//private RecyclerViewClickListener listener;
public DiasAdapter(Context context, ArrayList<Dia> dias, DiasListner diasListner) {
this.context = context;
this.dias = dias;
this.diasListner = diasListner;
}
//Aqui cria as visualizações
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//Criação da view
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_dias, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
final Dia dia = dias.get(position);
holder.imageCalendarioEnsaio.setImageResource(dia.getImgDias());
holder.textViewDiasSemana.setText(dia.getNomeDias());
//Pegando ação do clique do usuário na lista
//Pegando ação do clique do usuário na lista
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
diasListner.addDia(dia );
}
});
//Seta imagem
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public int getItemCount() {
return dias.size();
}
//Esssa classe MY VIEWHOLDER é responsável por guardar os dados antes de eles serem exibidos na tela
public class MyViewHolder extends RecyclerView.ViewHolder {
//INICILIZA VARIAVEL
ImageView imageCalendarioEnsaio;
TextView textViewDiasSemana;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
imageCalendarioEnsaio = itemView.findViewById(R.id.imageCalendarioEnsaio);
textViewDiasSemana = itemView.findViewById(R.id.textViewDiasSemana);
}
}
}
MY LISTENER
public interface DiasListner {
public void addDia(Dia dia);
}
Main class
package com.example.tocacomigo;
import android.Manifest;
import android.app.DatePickerDialog;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.tocacomigo.activity.Estilo;
import com.example.tocacomigo.adapter.DiasAdapter;
import com.example.tocacomigo.adapter.EstilosAdapter;
import com.example.tocacomigo.adapter.InstrumentosAdapter;
import com.example.tocacomigo.listner.DiasListner;
import com.example.tocacomigo.listner.EstilosListner;
import com.example.tocacomigo.listner.InstrumentoListner;
import com.example.tocacomigo.model.Musico;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class FinalizaCadastro extends AppCompatActivity implements InstrumentoListner, EstilosListner, DiasListner {
//Recycler DIAS ENSAIO------------------------------------------
RecyclerView recyclerViewDias;
ArrayList<Dia> dias;
DiasAdapter diasAdapter;
private List<String> diasString;
//Recycler ESTILOS MUSICAIS------------------------------------------
RecyclerView recyclerViewEstilos;
ArrayList<Estilo> estilos;
EstilosAdapter estilosAdapter;
private List<String> estilosString;
//---------------------------INSTRUMENTOS-------------------------------------------
RecyclerView recyclerViewInstrumentos;
ArrayList<Instrumento> instrumentos;
InstrumentosAdapter adapter_instrumentos;
private List<String> instrumentosString;
//Variaveis de Localização ------------
Button btnLocalizacaoMusico, btnFinalizarCadastro;
TextView textViewLocalizacao, textView1, textView2, textView4, textView6;
FusedLocationProviderClient fusedLocationProviderClient;
//----REFERENTE A DATA DE NASCIMENTO---------------
Button btnCalendario;
TextView textDataNasc, textIdade;
//----------------FIREBASE----------
private FirebaseAuth firebaseAuth;
private FirebaseDatabase database;
private Musico musico;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finalizarcadastro);
//----FIREBASE-----------------------------------
database = FirebaseDatabase.getInstance();
//-----------------------------------------------------------ESTILOS---------------------
recyclerViewEstilos = findViewById(R.id.recyclerEstilos);
recyclerViewDias = findViewById(R.id.recyclerViewDias);
recyclerViewInstrumentos = findViewById(R.id.recyclerViewInstrumentos);
//---------------------CRIANDO STRING DE ARRAYS DE ESTILOS ------
String[] nomeEstilo = {"Axé", "Black Music", "Blues", "Bossa Nova", "Chillout", "Classic Rock", "Clássico", "Country", "Dance", "Disco", "Electro Swing", "Electronica", "Emocore", "Fado", "Folk", "Forró", "Funk", "Funk Carioca", "Gospel/Religioso", "Gótico", "Grunge", "Hard Rock", "Hardcore", "Heavy Metal", "Hip Hop", "House", "Indie", "industrial", "infantil", "instrumental", "j-pop", "Jazz", "jovem Guarda", "K Pop", "Kizomba", "Metal", "MPB", "Músicas Gaúchas", "New Age", "New Wave", "Pagode", "Paino Rock", "Pop", "Pop/Funk", "Pop/Rock", "Pós Punk", "Post Rock", "Power Pop", "Progressivo", "Psicodelia", "Punk Rock", "R&B", "Rap", "Reggae", "Reggaeton", "Regional", "Rock", "Rock Alternativo", "Rockabilly", "Romântico", "Samba", "Samba Enredo", "Sertanejo", "Ska", "Soft Rock", "Soul Music", "Surf Music", "Tecnopop", "Trance", "Trap", "Trilha Sonora", "Trip Hop", "Tropical House", "Velha Guarda", "World Music",
};
//---------------------------ESTILO--------------------------------------------------
//Inicializando o arrayList
estilos = new ArrayList<>();
for (int i = 0; i < nomeEstilo.length; i++) {
Estilo estiloM = new Estilo(nomeEstilo[i]);
estilos.add(estiloM);
}
//Design horizontal ESTILO-------------------------------------------
LinearLayoutManager layoutManagerEstiloM = new LinearLayoutManager(
FinalizaCadastro.this, LinearLayoutManager.VERTICAL, false
);
recyclerViewEstilos.setLayoutManager(layoutManagerEstiloM);
recyclerViewEstilos.setItemAnimator(new DefaultItemAnimator());
//Inicializa EstilosAdapter------------------------------------------------ESTILOS
estilosAdapter = new EstilosAdapter(FinalizaCadastro.this, estilos, this);
//Seta adapter para RecyclerView
recyclerViewEstilos.setAdapter(estilosAdapter);
musico = getIntent().getParcelableExtra("musico");
//Localização
btnLocalizacaoMusico = findViewById(R.id.btnLocalizacaoMusico);
btnFinalizarCadastro = findViewById(R.id.btnFinalizarCadastro);
textViewLocalizacao = findViewById(R.id.textViewLocalizacao);
textView1 = findViewById(R.id.textView1);
textView2 = findViewById(R.id.textView2);
textView4 = findViewById(R.id.textView4);
textView6 = findViewById(R.id.textView6);
//Informaçoes de latitude e longitude por enquanto deixei invisiveis
textView1.setVisibility(View.GONE);
textView2.setVisibility(View.GONE);
textView4.setVisibility(View.GONE);
textView6.setVisibility(View.GONE);
instrumentosString = new ArrayList<>();
estilosString = new ArrayList<>();
diasString = new ArrayList<>();
//Incializando fusedLocationProviderClient
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
btnLocalizacaoMusico.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Checar Permissoes
if (ActivityCompat.checkSelfPermission(FinalizaCadastro.this
, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
//permissão concedida
getLocation();
} else {
//Permissão negada
ActivityCompat.requestPermissions(FinalizaCadastro.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 44);
}
}
});
}
private void getLocation() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
fusedLocationProviderClient.getLastLocation().addOnCompleteListener(new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
//Inicializa a localizacao
Location location = task.getResult();
if (location != null) {
try {
//Inicializa geoCoder
Geocoder geocoder = new Geocoder(FinalizaCadastro.this, Locale.getDefault());
//Inicializa lista de endereço
List<Address> address = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1
);
//Seta a latitude no textvIEW
textView1.setText(Html.fromHtml(
"<font color='#6200EE'><b>Latitude :</b><br></font>"
+ address.get(0).getLatitude()));
//Set Longitude
textView2.setText(Html.fromHtml(
"<font color='#6200EE'><b>Longitude :</b><br></font>"
+ address.get(0).getLongitude()));
//seta o país
textView4.setText(Html.fromHtml(
"<font color='#6200EE'><b>País :</b><br></font>"
+ address.get(0).getCountryName()
));
//seta o local
textView6.setText(Html.fromHtml(
"<font color='#6200EE'><b>Local:</b><br></font>"
+ address.get(0).getLocality()
));
//Seta o endereço
textViewLocalizacao.setText(Html.fromHtml(
"<font color='#6200EE'><br></font>"
+ address.get(0).getAddressLine(0)
));
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
//Este
btnFinalizarCadastro.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
DatabaseReference myRef = mDatabase.getReference("musicos");
String uuid = new SimpleDateFormat("yyyyMMddHHmmssSS").format(new Date());
musico.setInstrumentos(instrumentosString);
musico.setEstilos(estilosString);
Task<Void> users = myRef.child("users").child(uuid).setValue(musico);
users.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("Test", e.getMessage());
}
});
users.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d("Test", "s");
}
});
}
});
//----------------------------------------------------------------------
textDataNasc = (TextView) findViewById(R.id.textDataNasc);
textIdade = (TextView) findViewById(R.id.textIdade);
//Evento do Clique do botão calendário
btnCalendario = (Button) findViewById(R.id.btnCalendario);
btnCalendario.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pegaraData();
}
});
// btn_deslogar = (Button) findViewById(R.id.btnDeslogar);
// btn_deslogar.setOnClickListener(this);
//---------
Integer[] imgInstrumentos = {
R.drawable.ic_baixo,
R.drawable.ic_guitarra,
R.drawable.ic_bateria,
R.drawable.ic_vocalista,
R.drawable.ic_teclado};
String[] nomeInstrumento = {"baixo", "guitarra", "bateria", "vocalista", "tecladista"};
//----------------------------DIAS-----------------------------
Integer[] imgDias = {
R.drawable.ic_calendariodias,
R.drawable.ic_filtrarmusico,
R.drawable.ic_foto,
R.drawable.ic_fotogaleria,
R.drawable.ic_foto,
R.drawable.ic_addusuario,
R.drawable.ic_senha};
String[] nomeDias = {"segunda", "terça", "quarta", "quinta", "sexta", "sábado", "domingo"};
//Inicializar arraylist
dias = new ArrayList<>();
for (int i = 0; i < imgDias.length; i++) {
Dia diasMusico = new Dia(imgDias[i], nomeDias[i]);
dias.add(diasMusico);
}
//Layout Horizontal dos dias
LinearLayoutManager layoutManagerDias = new LinearLayoutManager(
FinalizaCadastro.this, LinearLayoutManager.HORIZONTAL, false
);
recyclerViewDias.setLayoutManager(layoutManagerDias);
recyclerViewDias.setItemAnimator(new DefaultItemAnimator());
//inicializa adapter
//Seta o adapater no recyclerviwq
recyclerViewDias.setAdapter(diasAdapter);
//Inicializar array
instrumentos = new ArrayList<>();
for (int i = 0; i < imgInstrumentos.length; i++) {
Instrumento instrumentosMusico = new Instrumento(imgInstrumentos[i], nomeInstrumento[i]);
instrumentos.add(instrumentosMusico);
}
// Layout horizontal dos instrumentos
LinearLayoutManager layoutManager = new LinearLayoutManager(
FinalizaCadastro.this, LinearLayoutManager.HORIZONTAL, false
);
recyclerViewInstrumentos.setLayoutManager(layoutManager);
recyclerViewInstrumentos.setItemAnimator(new DefaultItemAnimator());
//inicializa adapter
adapter_instrumentos = new InstrumentosAdapter(FinalizaCadastro.this, instrumentos, this);
diasAdapter = new DiasAdapter(FinalizaCadastro.this, dias,this);
//Configuração RecyclerView dos Instrumentos
recyclerViewInstrumentos.setAdapter(adapter_instrumentos);
}
//VER
// ---------------------------------------------------------------------------------------------------
//Aqui é para pegar a data do calendário referente ao nascimento do usuário
private void pegaraData() {
Calendar calendario = Calendar.getInstance();
int dia = calendario.get(Calendar.DAY_OF_MONTH);
int mes = calendario.get(Calendar.MONTH);
int ano = calendario.get(Calendar.YEAR);
//Criação do Objeto aqui eu pego as datas e exibo para o usuario
DatePickerDialog datePickerDialog = new DatePickerDialog(FinalizaCadastro.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
textDataNasc.setText(dayOfMonth + "/" + (month + 1) + "/" + year);
//Calcular idade
calcularIdade(dayOfMonth, month, year);
}
}, ano, mes, dia);
datePickerDialog.show();
}
//Calcula idade
private void calcularIdade(int diaNasc, int mesNasc, int anoNasc) {
Calendar calendario = Calendar.getInstance();
int diaAtual = calendario.get(Calendar.DAY_OF_MONTH);
int mesAtual = calendario.get(Calendar.MONTH);
int anoAtual = calendario.get(Calendar.YEAR);
//Verifinado a idade do músico
int idade = anoAtual - anoNasc;
if (mesNasc > mesAtual) {
idade--;
} else if (mesAtual == mesNasc) {
if (diaNasc > diaAtual) {
idade--;
}
}
textIdade.setText("Sua idade: " + idade);
}
//--------------------------------------------------------------------------
// Vai informar que o usuário selcionou um instrumento
@Override
public void addInstrumento(Instrumento instrumento) {
// Verifica se o item clicado já existe eu removo e sai da função
for (String item : this.instrumentosString) {
if (item.equals(instrumento.getNomeInstrumento())) {
this.instrumentosString.remove(item);
return;
}
}
initInstrumentosListString();
this.instrumentosString.add(instrumento.nomeInstrumento);
}
private void initInstrumentosListString() {
if (instrumentosString == null) {
instrumentosString = new ArrayList<>();
}
}
//---------------------FAZENDO ESTILOS
public void addEstilo(Estilo estilo) {
// Verifica se o item clicado já existe eu removo e sai da função
for (String item : this.estilosString) {
if (item.equals(estilo.getNomeEstilo())) {
this.estilosString.remove(item);
return;
}
}
initEstilosListString();
this.estilosString.add(estilo.nomeEstilo);
}
private void initEstilosListString() {
if (estilosString == null) {
estilosString = new ArrayList<>();
}
}
//------------------------DIAS
public void addDia(Dia dia) {
// Verifica se o item clicado já existe eu removo e sai da função
for (String item : this.diasString) {
if (item.equals(dia.getNomeDias())) {
this.diasString.remove(item);
return;
}
}
initDiasListString();
this.diasString.add(dia.nomeDias);
}
private void initDiasListString() {
if (diasString == null) {
diasString = new ArrayList<>();
}
}
}
MY ITEM DAYS
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/recyclerViewDias"
android:layout_width="101dp"
android:layout_height="117dp"
android:layout_marginEnd="10dp"
android:gravity="center"
android:orientation="vertical"
android:paddingStart="10dp">
<ImageView
android:id="@+id/imageCalendarioEnsaio"
android:layout_width="73dp"
android:layout_height="66dp"
android:src="@drawable/foto" />
<TextView
android:id="@+id/textViewDiasSemana"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="Dias"
android:textSize="10sp">
</TextView>
</LinearLayout>
</RelativeLayout>
MY DAY CLASS
package com.example.tocacomigo;
public class Dia {
String nomeDias;
Integer imgDias;
public Dia(Integer imgDias, String nomeDias) {
this.imgDias = imgDias;
this.nomeDias = nomeDias;
}
public Integer getImgDias() {
return imgDias;
}
public String getNomeDias() {
return nomeDias;
}
}