上午教程以下位置: http://www.mydroid.apnafundaz.com/2010/07/todolist-application-in-android-step-by-step-guide-with-screen-shots/Android的简易待办事项清单应用程序创建一个简单的待办事项列表应用程序无法正常呈现
完成并没有错误,但我的应用程序不会出现像在这个例子中,而它看起来像这样 - 基本上EditText出现,但没有ListView与以前的任务...
由于没有错误,很难找出我要去哪里错了,但作为我的合作伙伴也做同样的教程,并提出了完全相同的结果,我认为这可能是一个问题,啧啧 - 任何建议非常感谢!
以防万一,这是我的java文件:
package com.example.helloworld;
import java.util.ArrayList;
import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate your view
setContentView(R.layout.main);
// Get references to UI widgets
ListView myListView = (ListView)findViewById(R.id.myListView);
final EditText myEditText = (EditText)findViewById(R.id.myEditText);
// Create the array list of todo items
final ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adaptor to bind the array to the listview
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
todoItems);
// Bind the array adapter to the listview
myListView.setAdapter(aa);
myEditText.setOnKeyListener(new OnKeyListener(){
public boolean onKey(View v, int keyCode, KeyEvent event){
if(event.getAction() == KeyEvent.ACTION_DOWN)
if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
{
todoItems.add(0,myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("");
return true;
}
return false;
}
}
);
}
}
这里是我的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="New to Do Item"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
为什么你要关注这个尴尬的教程?这不是特别好:它没有教授关于`ListActivity`,它没有讲授数据持久性,而且代码大多写得不好,而且很糟糕。 http://developer.android.com/有很多不错的教程,为什么不从那里开始? – Felix 2010-12-02 14:10:50
我已经在我的博客中编写了关于TODO应用程序的教程。有关详细信息,请访问 http://www.harshaprabha.blogspot.com/ – Harsha 2011-06-24 08:14:46