如何使听者当用户开始输入

如何使听者当用户开始输入

本文介绍了如何使听者当用户开始输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的机器人工作室和消防基地,并就如何使听者一样,如果用户键入在编辑文本字段消防基础的用户的价值得到了股票设计一个聊天应用程序将变成真正的并且当用户没有输入数值就变成假。?我在寻找这种解决方案的一个星期左右,并没有发现有关我的研究,任何回答。

如何把TextWatcher?

 公共类MainActivity扩展AppCompatActivity {


私人的EditText EDITTEXT;
私人的ListView ListView的;


@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);

    计数器= 0;
    Firebase.setAndroidContext(本);
    最后的火力地堡火力点=新的火力地堡(https://samp-is.firebaseio.com/);


    EDITTEXT =(EditText上)findViewById(R.id.editText);
    ListView的=(的ListView)findViewById(R.id.listView);

    listView.setAdapter(新MessageAdapter(这一点,Message.class,R.layout.fragment_message,firebase.child(聊天)));

    Button按钮=(按钮)findViewById(R.id.button);

    button.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            反++;

            消息消息=新的Message();

            message.setMessage(editText.getText()的toString());
            editText.setText();
            message.setAuthor(姓名);
            message.setCounter(柜);
            firebase.child(聊天)推()的setValue(消息)。;


        }
        });
    }
}
 

解决方案

您是否在寻找 onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数)

从引用的 TextWatcher

本次活动将发射一个用户输入了什么东西到的EditText

I am designing a chat application using android studio and fire-base and got stock on how to make a listener like if the user is typing on the edit-text field The value of the user on fire-base will changed into true and when the user is not typing the value will become false.? I am looking for this solution for about a week, and didn't find any answer regarding on my researches.

How to put TextWatcher?

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);

    counter = 0;
    Firebase.setAndroidContext(this);
    final Firebase firebase = new Firebase("https://samp-is.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) {
            counter++;

            Message message = new Message();

            message.setMessage(editText.getText().toString());
            editText.setText("");
            message.setAuthor("Name");
            message.setCounter(counter);
            firebase.child("chat").push().setValue(message);


        }
        });
    }
}
解决方案

Are you looking for onTextChanged(CharSequence s, int start, int before, int count)?

Quoting from the TextWatcher

This event will fired one user entered something into EditText.

这篇关于如何使听者当用户开始输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:37