我是Android的新手,并被要求开发Android的应用程序.我正在使用Android 2.2.我遇到的问题是,一旦我点击基本教程中的"添加"按钮,就会出现客户端的名称,但它不会那样工作.单击按钮后,列表视图中未显示该名称.
这里的代码:
public class MainActivity extends Activity implements OnClickListener,
OnKeyListener {
ArrayList<String> appointment;
ArrayAdapter<String> aa;
EditText editText1;
Button addButton;
ListView listView1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText1 = (EditText)findViewById(R.id.editText1);
addButton = (Button)findViewById(R.id.addButton);
listView1 = (ListView)findViewById(R.id.listView1);
addButton.setOnClickListener(this);
editText1.setOnKeyListener(this);
appointment = new ArrayList<String>();
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
appointment);
listView1.setAdapter(aa);
}
private void addItems(String item){
if (item.length()>0){
this.appointment.add(item);
this.aa.notifyDataSetChanged();
this.editText1.setText("");
}
}
public void onClick(View v) {
if(v==this.addButton){
this.addItems(this.editText1.getText().toString()); …Run Code Online (Sandbox Code Playgroud)