Я закончил свою программу, чтобы показать данные.Данные будут отображаться при нажатии кнопки.Эта программа использует Firebase
и FirebaseRecyclerAdapter
.Но он не отображает данные в моем RecyclerView.Я не знаю, что не так.
Я думаю, что есть проблема в функции KamusViewHolder
, но я все еще не знаю, что не так.
JawaActivity.java
public class JawaActivity extends AppCompatActivity {
private EditText mSearchField;
private ImageButton mSearchButton;
private RecyclerView mResultList;
DatabaseReference mKamusDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jawa);
mKamusDatabase = FirebaseDatabase.getInstance().getReference("Employees");
mSearchField = (EditText) findViewById(R.id.searchField);
mSearchButton = (ImageButton) findViewById(R.id.searchButton);
mResultList = (RecyclerView) findViewById(R.id.resultList);
mResultList.setHasFixedSize(true);
mResultList.setLayoutManager(new LinearLayoutManager(this));
mSearchButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view){
String searchText = mSearchField.getText().toString();
firebaseKamusSearch(searchText);
}
});
}
private void firebaseKamusSearch(String searchText) {
Toast.makeText(JawaActivity.this, "Mulai Mencari", Toast.LENGTH_LONG).show();
Query query = mKamusDatabase.orderByChild("Employees").startAt(searchText).endAt(searchText);
FirebaseRecyclerOptions<Kamus> options = new FirebaseRecyclerOptions.Builder<Kamus>().setQuery(query, Kamus.class).build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Kamus, KamusViewHolder>(options) {
@Override
public KamusViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.message for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.teks_jawa, parent, false);
return new KamusViewHolder(view);
}
@Override
protected void onBindViewHolder(KamusViewHolder holder, int position, Kamus model) {
holder.Indonesia.setText(model.getIndonesia());
holder.Kramainggil.setText(model.getKramainggil());
holder.Kramaalus.setText(model.getKramaalus());
holder.Ngoko.setText(model.getNgoko());
}
};
mResultList.setAdapter(adapter);
}
public class KamusViewHolder extends RecyclerView.ViewHolder{
View mView;
TextView Indonesia;
TextView Kramainggil;
TextView Kramaalus;
TextView Ngoko;
public KamusViewHolder(View itemView)
{
super(itemView);
mView = itemView;
Indonesia = (TextView) mView.findViewById(R.id.Indonesia);
Kramainggil = (TextView) mView.findViewById(R.id.Kramainggil);
Kramaalus = (TextView) mView.findViewById(R.id.Kramaalus);
Ngoko = (TextView) mView.findViewById(R.id.Ngoko);
}
}
}
Kamus.Java
public class Kamus {
public String indonesia;
public String kramaalus;
public String kramainggil;
public String ngoko;
public Kamus(){
}
public Kamus(String indonesia, String kramaalus, String kramainggil, String ngoko) {
this.indonesia = indonesia;
this.kramaalus = kramaalus;
this.kramainggil = kramainggil;
this.ngoko = ngoko;
}
public String getIndonesia() {
return indonesia;
}
public void setIndonesia(String indonesia) {
this.indonesia = indonesia;
}
public String getKramaalus() {
return kramaalus;
}
public void setKramaalus(String kramaalus) {
this.kramaalus = kramaalus;
}
public String getKramainggil() {
return kramainggil;
}
public void setKramainggil(String kramainggil) {
this.kramainggil = kramainggil;
}
public String getNgoko() {
return ngoko;
}
public void setNgoko(String ngoko) {
this.ngoko = ngoko;
}
}