http://www.vogella.com/articles/AndroidSQLite/article.html
y tengo un fallo en la línea 6: Main can not be resolved or is not a field
setContentView(R.layout.main);
Los import los tengo todos y tengo creado main.xml. A ver si alguien me puede ayudar.
Cita:
public class TestDatabaseActivity extends ListActivity {
private CommentsDataSource datasource;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datasource=new CommentsDataSource(this);
datasource.open();
List<Comment> values=datasource.getAllComments();
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,android.R.layout.simple _list_item_1,values);
setListAdapter(adapter);
}
public void onClick(View view){
@SuppressWarnings("unchecked")
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) getListAdapter();
Comment comment = null;
switch(view.getId()){
case R.id.add:
String[] comments = new String[]{ "Cool","VeryNice","Hate it"};
int nextInt= new Random().nextInt(3);
comment= datasource.createComment(comments[nextInt]);
adapter.add(comment);
break;
case R.id.delete:
if (getListAdapter().getCount()>0){
comment = (Comment) getListAdapter().getItem(0);
datasource.deleteComment(comment);
adapter.remove(comment);
}
break;
}
adapter.notifyDataSetChanged();
}
@Override
protected void onResume(){
datasource.open();
super.onResume();
}
@Override
protected void onPause(){
datasource.close();
super.onPause();
}
}
Gracias public class TestDatabaseActivity extends ListActivity {
private CommentsDataSource datasource;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datasource=new CommentsDataSource(this);
datasource.open();
List<Comment> values=datasource.getAllComments();
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,android.R.layout.simple _list_item_1,values);
setListAdapter(adapter);
}
public void onClick(View view){
@SuppressWarnings("unchecked")
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) getListAdapter();
Comment comment = null;
switch(view.getId()){
case R.id.add:
String[] comments = new String[]{ "Cool","VeryNice","Hate it"};
int nextInt= new Random().nextInt(3);
comment= datasource.createComment(comments[nextInt]);
adapter.add(comment);
break;
case R.id.delete:
if (getListAdapter().getCount()>0){
comment = (Comment) getListAdapter().getItem(0);
datasource.deleteComment(comment);
adapter.remove(comment);
}
break;
}
adapter.notifyDataSetChanged();
}
@Override
protected void onResume(){
datasource.open();
super.onResume();
}
@Override
protected void onPause(){
datasource.close();
super.onPause();
}
}