这是我的firebase数据。 我想使用在最后一页(b)中键入的单词来查找我的数据库中是否有类似的数据。 就像我键入tt一样,它会显示所有包含tt的标题(例如,ttttt Tttd3 tt456) 我该怎么办?
public class List extends AppCompatActivity {
private DatabaseReference mRef;
private static final String TAG = "List";
private ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
list = (ListView)findViewById(R.id.listview);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
android.R.id.text1);
list.setAdapter(adapter);
I take the keywords from here.
//Bundle bundle = getIntent().getExtras();
//String b = bundle.getString("text");
//Query query = mRef.child("users").orderByChild("username").startAt(b);
DatabaseReference reference_contacts = FirebaseDatabase.getInstance().getReference("商品");
//Query query = mRef.equalTo(b);
reference_contacts.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
adapter.clear();
for (DataSnapshot ds : dataSnapshot.getChildren() ){
adapter.add(ds.child("titles").getValue().toString());
}
}
@Override
public void onCancelled(DatabaseError error) {
Log.w(TAG, "Failed to read value.", error.toException());
}
});
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent();
intent.setClass(getApplicationContext(),ProductPage.class);
String a = ""+position;
Bundle bundle = new Bundle();
bundle.putString("num",a);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}
我想使用最后一页(b)中输入的单词来查找我的数据库中是否有类似的数据。 就像我键入tt一样,它会显示所有包含tt的标题(例如,ttttt Tttd3 tt456) 我该怎么办?