I'm following through the first TodoList example in Reto Meier's wonderful Professional Android 4 Application Development, but having a slight problem I haven't been able to work out. Here's the code as it is:
package com.paad.todolist;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;
import android.widget.ListView;
public class ToDoListActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_do_list);
// Get references to UI widgets
ListView myListView = (ListView) findViewById(R.id.myListView);
final EditText myEditText = (EditText) findViewById(R.id.myEditText);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_to_do_list, menu);
return true;
}
}
This differs slightly from the book, which uses main.xml. The later Eclipse creates activity_to_do_list.xml, which has the same content as the book.
My original problem was that R.id.myListView and R.id.myEditView weren't being recognised, and I tried Project | Clean to solve this. This made things worse, now "R cannot be resolved to a variable". I suspect the clean removed generated code.
Also I have an error in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.paad.todolist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ToDoListActivity"
android:label="@string/title_activity_to_do_list" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@string/title_activity_to_do_list doesn't work, not too surprising as the clean seems to have removed res\values\string.xml too.
Help!