views:

831

answers:

2

I have a listview that I want to add event listener to it. The following simple code exits with "Source Not Found" when debugging.

I remembered using exactly the same code for Button object and it did not caused any problem.

mArticleList = (ListView)findViewById(R.id.ArticleList);
    populateArticleList();
    mArticleList.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {               
            launchFullArticle();
            ;
        }


    });

    protected void launchFullArticle() {
    // TODO Auto-generated method stub
    Context context = getApplicationContext();
    CharSequence text = "Hello toast!";
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();

}
+3  A: 

If it's a list why you're assigning onClickListener - use onItemClickListener

Alex Volovoy
Yes, the following code works. mArticleList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View v, int position, long id) { //... launchFullArticle(id); } });
Yang
+3  A: 

"Source Not Found" when debugging means you haven't linked the Android source code into Eclipse, and yet you are trying to step into that code. The debugger can't step into it if the source isn't available to it.

You could import the Android source into Eclipse via something like this or you could just step over the Android methods when debugging.

mbaird