[英]If else statement in java (Android)
can anyone help me on how to create an if else statement in android java.任何人都可以帮助我如何在 android java 中创建 if else 语句。 ? ? i am doing a chat app using firebase ,and i got stock because of the notification.我正在使用 firebase 做一个聊天应用程序,由于收到通知,我得到了库存。 now i would like to increase the number of messages every time i chat you.现在我想增加每次和你聊天的消息数量。 Like in example below ,let say i am john".就像下面的例子,假设我是约翰”。
John: hi jacki
Jacki: hello
therefore: if i will check my firebase dashboard the numMessage is counted as 1 .因此:如果我将检查我的 firebase 仪表板,则 numMessage 被计为 1 。 because i did chat jacki once in our conversation.因为我在我们的谈话中确实和 jacki 聊过一次。
Heres my code/这是我的代码/
package com.example.mypc.thisissample;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.firebase.client.Firebase;
public class MainActivity extends AppCompatActivity {
private EditText editText;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
final Firebase firebase = new Firebase("https://example.firebaseio.com/");
editText = (EditText) findViewById(R.id.editText);
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(new MessageAdapter(this, Message.class, R.layout.fragment_message, firebase.child("chat")));
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message message = new Message();
message.setMessage(editText.getText().toString());
message.setAuthor("Name");
firebase.child("chat").push().setValue(message);
editText.setText("");
}
});
}
}
I didn't get what you really need, please explain a little better.我没有得到你真正需要的东西,请解释好一点。 But if you are asking for if/else statement in java try to read some java cookbook first!但是,如果您在 Java 中要求 if/else 语句,请先尝试阅读一些 Java 食谱!
Anyway反正
if(statement) {
} else {
}
First read de numCount from the firebase and store it on a localVariable首先从 firebase 读取 de numCount 并将其存储在 localVariable 上
https://www.firebase.com/docs/android/guide/retrieving-data.html https://www.firebase.com/docs/android/guide/retrieving-data.html
Then every time someone press the send button push the number to the firebase.然后每次有人按下发送按钮时,都会将数字推送到火力基地。
https://www.firebase.com/docs/android/guide/saving-data.htmlhttps://www.firebase.com/docs/android/guide/saving-data.html
Here you have an example of an increment这里有一个增量示例
final Firebase upvoteref = new Firebase("https://shareurday.firebaseio.com/Message/"+msg_id+"/upvotes");
upvoteref.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(final MutableData currentData) {
if (currentData.getValue() == null) {
currentData.setValue(1);
} else {
currentData.setValue((Long) currentData.getValue() + 1);
}
return Transaction.success(currentData);
}
public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {
if (firebaseError != null) {
System.out.println("Firebase counter increment failed.");
} else {
System.out.println("Firebase counter increment succeeded.");
}
}
});
Hope it helps希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.