我正在使用手势侦听器监视用户的操作,但是当应用程序弹出对话框时,我不知道如何将手势侦听器切换为对话框事件并处理事件按钮(确定和取消),可以有人给我建议吗?
伪代码是这样的
public class MainActivity extends FragmentActivity
implements ConnectionEventListener{
......
// when connection established,
// pop a diaglog (android native diaglog with listview and its adapter) to ask user to select ok or cancel button
@Override
public void onUpdateAlert(final int event, final String message){
}
// gesture listener
// if a dialog pops up, the pose can be used to select OK or cancel
@Override
public void onDetected(Hand pose){
}
}
我遇到的问题不是按钮侦听器。实际上,我有两个监听器同时工作,一个监听事件,另一个监听姿势。当事件到来时,该事件将弹出一个对话框以选择“确定”或“取消”。同时,姿势监听器仍然有效。我想知道这种情况何时发生,如何在弹出对话框时使用姿势侦听器选择“确定”或“取消”?
答案 0 :(得分:1)
我认为我们需要这样的东西:
Imports System.Xml
Public Class frmStudentGrades
' Author: Victoria Farrell
' Date: August 2018
'Purpose: To calculate the display the graded results of student marks entered.
Dim intQuantity As Integer ' This variable handles the total number of students in the class
Dim strArray(intQuantity, 5) As String ' This Array handles all the data - student names, marks, percentages and final grades
Dim Counter As Integer ' This variable counts how many students are entered and handles each row in the array.
Private Sub btnSize_Click(sender As Object, e As EventArgs) Handles btnSize.Click
' This subroutine reads in the number of students in the class and informs the user to enter student data.
' Counter is set to zero at this point to intialise the first point in the array.
intQuantity = Val(txtQuantity.Text)
Counter = 0
MsgBox("Your class has " & intQuantity & " students. Please enter each student and their marks one by one.")
End Sub
Private Sub btnStudent_Click(sender As Object, e As EventArgs) Handles btnStudent.Click
Dim strArray(intQuantity, 5) As String
' The array is defined in terms of the size of the class (numbers of students)
If Counter < intQuantity Then
MsgBox("You have entered student number " & (Counter + 1))
' This message informs the user that they have entered data into the array and how many students have been entered based on the counter.
strArray(Counter, 0) = txtGivenName.Text ' The student given name is entered into the first column of the Counter-th row
strArray(Counter, 1) = txtFamilyName.Text ' The student family name is entered into the second column of the Counter-th row
strArray(Counter, 2) = txtResult.Text ' The student's result is entered into the third column of the Counter-th row
strArray(Counter, 3) = txtTotal.Text ' The total marks for the assessment is entered into the fourth column of the Counter-th row
strArray(Counter, 4) = CStr(Math.Round(((Val(strArray(Counter, 2)) / Val(strArray(Counter, 3))) * 100), 2))
' This calcuates the percentage of the results and enters it into the fifth column of the Counter-th row
' This IF statement tests the percentage and decides what the Letter Grade will be allocated. this goes into the sixth column.
If strArray(Counter, 4) < 50 Then
strArray(Counter, 5) = "F"
ElseIf strArray(Counter, 4) >= 50 And strArray(Counter, 4) < 60 Then
strArray(Counter, 5) = "E"
ElseIf strArray(Counter, 4) >= 60 And strArray(Counter, 4) < 70 Then
strArray(Counter, 5) = "D"
ElseIf strArray(Counter, 4) >= 70 And strArray(Counter, 4) < 80 Then
strArray(Counter, 5) = "C"
ElseIf strArray(Counter, 4) >= 80 And strArray(Counter, 4) < 90 Then
strArray(Counter, 5) = "B"
ElseIf strArray(Counter, 4) >= 90 And strArray(Counter, 4) <= 100 Then
strArray(Counter, 5) = "A"
End If
' The content of the entire row is added to the list box to be displayed.
listResults.Items.Add(strArray(Counter, 0) & " " & strArray(Counter, 1) & " " & strArray(Counter, 2) & "/" & strArray(Counter, 3) & " : " & strArray(Counter, 4) & "% Final Grade: " & strArray(Counter, 5))
' One is added to the counter because the row is complete and we need to count it.
Counter = Counter + 1
' when the Counter reaches the size of the class a warning will appear if they try to enter more students.
ElseIf Counter = intQuantity Then
MsgBox("You have entered all the students into your class")
End If
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
' This subroutine allows the user to clear the data from all the text boxes.
txtGivenName.Text = " "
txtFamilyName.Text = " "
txtResult.Text = " "
txtTotal.Text = " "
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
' This subroutine allows the user to close the program.
Me.Close()
End Sub
Private Sub btnXml_Click(sender As Object, e As EventArgs) Handles btnXml.Click
Dim writer As New XmlTextWriter("StudentResults.xml", System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("Table")
For i As Integer = 0 To intQuantity
createNode((i + 1), strArray(i, 0), strArray(i, 1), strArray(i, 2), strArray(i, 3), strArray(i, 4), strArray(i, 5), writer)
Next i
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
End Sub
Private Sub createNode(ByVal intQuantity As String, pNumber As String, pGiven As String, pFamily As String, pResult As String, pTotal As String, pPercent As String, pGrade As String)
Dim writer As New XmlTextWriter("StudentResults.xml", System.Text.Encoding.UTF8)
For i As Integer = 0 To intQuantity
writer.WriteStartElement("Student_Number")
writer.WriteString(pNumber)
writer.WriteEndElement()
writer.WriteStartElement("Student_Given_Name")
writer.WriteString(pGiven)
writer.WriteEndElement()
writer.WriteStartElement("Student_Family_Name")
writer.WriteString(pFamily)
writer.WriteEndElement()
writer.WriteStartElement("Student_Result")
writer.WriteString(pResult)
writer.WriteEndElement()
writer.WriteStartElement("Student_Total")
writer.WriteString(pTotal)
writer.WriteEndElement()
writer.WriteStartElement("Student_Percentage")
writer.WriteString(pPercent)
writer.WriteEndElement()
writer.WriteStartElement("Student_Grade")
writer.WriteString(pGrade)
writer.WriteEndElement()
Next
End Sub
我们可以像这样从SomeActivity调用showDialog:
public static void showDialog(SomeActivity someActivity, final SomeCallback callBack {
final Dialog dialog = new Dialog(someActivity);
dialog.setContentView(R.layout.dialog_with_buttons);
// OK button ...
Button dialogButtonOk = dialog.findViewById(R.id.btn_ok);
dialogButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
callBack.execute(true);
dialog.dismiss();
}
});
// Cancel button ...
Button buttonCancel = dialog.findViewById(R.id.btn_cancel);
buttonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callBack.execute(false);
dialog.dismiss();
}
});
dialog.show();
}
和回调接口:
showDialog(this, new SomeCallback () {
@Override
public void execute(boolean status) {
if (status) {
...
} else {
...
}
}
});
祝你好运
伪代码可以像这样:
public interface SomeCallback {
void execute(boolean status);
}