其實我決定不使用推的,因爲所有我想要的是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
}
}
謝謝你的幫助,無論如何,我將用於未來的項目推!
如果它幫助請upvote並標記爲已回答。如果不寫一個反饋,以便我知道還需要什麼。 :) –
謝謝你的建議!我嘗試添加依賴項並同步項目,但會彈出此錯誤: 錯誤:(32,0)啓動失敗: 構建文件'\ app \ build.gradle':32:期望'}',找到' ,'@ line 32,column 65. roid:android-async-http:1.4.9',// for o ^ – Timppa
編輯:修正它通過添加分號而不是逗號。奇怪,但會告訴我做完 – Timppa