任何人都可以帮助我在这一点上受到打击我想在同一个窗口上显示用户输入的文本andriod应用程序。我想在屏幕上显示文本框的值,就像chatapps
一样这是我的主要代码.xml
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle("aakash");
SetContentView(R.id.lst);
Button b = (Button) findViewById(R.id.sendbtn);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(android.view.View v) {
startActivity(new Intent(View.this,View.class));
}
});
}
答案 0 :(得分:1)
你需要在xml-layout中放置一个listView。然后在.java文件中进行了这些更改:
final ArrayList<String> messages = new ArrayList<String>();
//在每个按钮上按下添加消息到messageList
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(android.view.View v) {
messages.add (YourWrittenText);
}
});
//用消息数组
填充listViewfinal ListView listview = (ListView) findViewById(R.id.listview);
答案 1 :(得分:0)
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ButtonActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button);
}
public void setText(){
Button myButton = (Button)findViewById(R.id.button1);
final TextView myText = (TextView)findViewById(R.id.text1);
final EditText myInput = (EditText)findViewById(R.id.edit);
myButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
myText.setText(myInput.getText());
}
});
}
}
this way its work