Am trying to get my setOnItemClickListener working, but when I add the method, Eclipse says that I should remove the "@Override" annotation, if I do, the listener don't work. The thing is that I need to capture the "click" event and do something... Here is my method:
list.setOnItemClickListener(new OnItemClickListener() {
@Override //<-- this is the annotation that eclipse says I should remove
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
Am really sure that the problem is not the method itself, i suppose that it's something else. Please take a look to my Activity and tell me what am doing wrong:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Intent;
import android.database.SQLException;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
public class Sounds extends Activity{
ListView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_table);
list=(ListView)findViewById(R.id.list);
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
DB_Helper myDbHelper = new DB_Helper(this);
try {
myDbHelper.createDataBase();
}catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
String[] columns = new String[3];
columns[0] = "id_Category";
columns[1] = "category_name";
columns[2] = "image_name";
songsList = myDbHelper.selectAll("Categories",columns);
}catch(SQLException sqle){
throw sqle;
}
adapter = new LazyAdapter(this, songsList);
list.setAdapter(adapter);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//ToDo something...
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about_sounds, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.about_sounds_item1:
Intent talesToLearnActivity = new Intent(Sounds.this, AboutSounds.class);
startActivity(talesToLearnActivity);
break;
default:
break;
}
return true;
}
}
If I remove the annotation, my method dont capture the event. If I do not remove it, my app dont compile. BTW Am working with Android 2.2 SDK
Check project properties and make sure that Java Compiler -> JDK Compliance -> Complier Compliance Level
is 1.6.
check properties in your project and make sure that Java Compiler -> JDK Compliance -> Complier Compliance Level is 1.6. otherwise it will not been work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With