状況:私はリストビューでクラスのリストを持っています。それは正常に動作しています。さて、リスト項目をクリックすると、私が表示したいとき重複名から1つの値を取得するにはどうすればよいですか?
:
English
Math
French
これは、クラスのデータベースです:私はこのようなリスト内のクラスを取得することができていますそのクラスのセクションであるので、English
リスト項目をクリックすると、そのクラスのセクションに警告ダイアログが表示されます。私はこのようなことを行うことができる午前:
listclasses.setLongClickable(true);
listclasses.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final String selectedFromList = (String) listclasses.getItemAtPosition(position);
final DatabaseReference retriev = FirebaseDatabase.getInstance().getReference().child("Class");
retriev.orderByChild("Classname").equalTo(selectedFromList).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data: dataSnapshot.getChildren()){
String key=data.getKey();
DatabaseReference referes=FirebaseDatabase.getInstance().getReference().child("Class");
referes.orderByKey().equalTo(key).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
String section=datas.child("section").getValue().toString();
LayoutInflater li = LayoutInflater.from(StudentSearchActivity.this); //inflate converts xml to a view object to use in code
View promptsView = li.inflate(R.layout.info, null); //two parameters, the xml and the root(null means the layout is a child of viewgroup
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
StudentSearchActivity.this); /*alertdialog.builder class,creates a builder for alert dialog, parameter is context */
alertDialogBuilder.setView(promptsView);
final TextView sections = (TextView) promptsView.findViewById(R.id.sections);
sections.setText(section);
alertDialogBuilder.setCancelable(true); //true can be canceled with back key
alertDialogBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alertDialog = alertDialogBuilder.create(); //creates alert dialog from builder
alertDialog.show();
}}
問題:私は同じクラス名例English
を持っていますが、それぞれのセクションにあるとき、私はアイテムの長いクリックで両方のセクションを取得します。例:
手順1:English
の項目を長くクリックします。
手順2:セクション503の警告ダイアログが表示されます。
ステップ3:バックプレスまたはok
を押すと、セクション:402の別のアラートダイアログが表示されます。
したがって、両方のセクションが同じ名前であるため、1つのクラスを長時間クリックすると表示されますが、これは間違っています。その英語クラスのセクションのみが表示され、他の英語クラスをクリックすると、この英語クラスのセクションも表示されます。これはFirebaseで解決できますか?
私はaddListenerForSingleValueEvent
を使用していますが、コードではClassname
というデータベースも使用しています。
ですか? –
私はそれが解決できるかどうか尋ねる?そしてどうやって?私はちょうど両方のセクションではなく、重複した名前を長時間クリックしたいのです –
リストに1つの "英語"を表示するには??? –