Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Studio:以“发送文本”;文本框“;_Java_Android_Text_Android Edittext - Fatal编程技术网

Java Android Studio:以“发送文本”;文本框“;

Java Android Studio:以“发送文本”;文本框“;,java,android,text,android-edittext,Java,Android,Text,Android Edittext,我正在尝试用一种类似“feed”的方法来做一个应用程序,在这个应用程序中,你输入消息,文本消息就会出现在屏幕的顶部。 就像messenger应用程序一样,它发送文本,但没有数据库。 这是一个没有internet连接的本地应用程序 所以我只想在视图的顶部弹出“EditText”的消息,每当我写下另一条消息时,最上面的消息会下降“1步”,最新的消息会在顶部 我知道之前可能会有关于这个/的教程,但我真的不知道如何按名称找到它,因为我的谷歌搜索结果只会返回一个方法,通过一些SMS方法向我发送真实的文本消

我正在尝试用一种类似“feed”的方法来做一个应用程序,在这个应用程序中,你输入消息,文本消息就会出现在屏幕的顶部。 就像messenger应用程序一样,它发送文本,但没有数据库。 这是一个没有internet连接的本地应用程序

所以我只想在视图的顶部弹出“EditText”的消息,每当我写下另一条消息时,最上面的消息会下降“1步”,最新的消息会在顶部


我知道之前可能会有关于这个/的教程,但我真的不知道如何按名称找到它,因为我的谷歌搜索结果只会返回一个方法,通过一些SMS方法向我发送真实的文本消息。

请查看此库:


我想这正是您所需要的,而且文档中有一些示例

实际上我决定不使用Pusher,因为我想要的只是打印到布局的TextView,然后每当创建另一个TextView时,它都会位于另一个位置。以下是它的脚本:

public void sendMessage(View v) {

    EditText mEdit = (EditText) findViewById(R.id.editText);
    String feedMsg = mEdit.getText().toString();
    if (feedMsg.equals("")) {
        // Do not send the message
    } else {
        View linLayout = findViewById(R.id.linLayout);

        TextView newMsg = new TextView(this);

        newMsg.setText("Player just created a group called " + feedMsg + "!\n" + getDate());
        newMsg.setId(5);
        newMsg.setTextSize(20);
        newMsg.setBackgroundColor(Color.parseColor("#F655F080"));
        newMsg.setPadding(20, 20, 20, 20);
        newMsg.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        ((LinearLayout) linLayout).addView(newMsg);
        mEdit.setText(""); // Clears the text
        hideSoftKeyboard(MainActivity.this); // Hides the keyboard

        Toast msgToast = Toast.makeText(getApplicationContext(), "Message sent!", Toast.LENGTH_SHORT);
        msgToast.show(); // Shows the notification about the successful message
    }

}

不管怎样,谢谢你的帮助,我将在未来的项目中使用pusher

如果有帮助,请投票并标记为已回答。如果没有,请写一份反馈,以便我知道还需要什么。:)谢谢你的建议!我试图添加依赖项并同步项目,但此错误将弹出:错误:(32,0)启动失败:生成文件“\app\build.gradle”:32:预期“}”,找到“,@第32行,第65列。roid:android async http:1.4.9',//对于o^EDIT:通过添加分号而不是逗号来修复它。奇怪,但我会在离开后通知你,很高兴我能帮上忙。如果您用勾号标记为已回答,那就太好了。