dman13146
dman13146

Reputation: 11

Cannot resolve symbol "OnItemClickListener"

So me and my team are developing an app regarding news Articles. The idea of the script is to be able to tap a name of an article from a top 20 list to get to the actual article. As easy as this should be, we've ran into errors with this code.

    package com.example.joseph.straightforwardlogin;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.EditText;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView;



import static com.example.joseph.straightforwardlogin.R.layout.activity_artical__view;

public class UserArea extends AppCompatActivity{

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_area);



        String[] articles = {"1.  Apple has criticized a decision by the Trump administration to withdraw protections for transgender students in public schools\n",
                "2. Google's charitable arm is pumping $11.5 million into 10 organizations fighting for racial justice\n", "3. More than 400,000 plastic toy frogs recalled\n",
                "4. Teen inspires first transgender doll\n", "5. Nick Cannon is a dad again\n", "6. John Travolta transforms into John Gotti\n",
                " 7. You can sail around the world ... for $55,000\n"," 8. Trump's former Ferrari is heading to auction\n"," 9. This company makes food packaging out of bamboo to cut down on trash\n",
                " 10. Immigrants: These cities want you!\n", " 11. Router hacker suspect arrested at Luton Airport\n", "12. Pakistan airline admits taking extra passengers in aisle\n",
                "13. McDaniel president takes on role with National Association of Independent Colleges and Universities\n ", "14. White House Spokesman Predicts More Federal Action Against Marijuana\n ",
                " 15. Uber Will Investigate Sexual Harassment Claims By Engineer\n", "16. 71 Degrees In February: Temperatures In Boston And Buffalo Rewrite Record Book ",
                " 17. Trump Will Be First President In 36 Years To Skip White House Correspondents Dinner\n", " 18. When You Love An Old Dog, Managing Care Can Be A Challenge\n", "19. Trump declines to attend White House correspondents' dinner\n",
                " 20. Teen wants to be guardian of sister after both parents die"};

        ListView listView = (ListView) findViewById(R.id.top20list);
        ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, articles);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
                        public void OnItemClickListener(AdapterView<?> parent, View view, int position, long id){
                        Intent nextActivity = new Intent(UserArea.this, Artical_View.class);
                        startActivity(nextActivity);
            }

        });







}

}

We keep getting Cannot resolve symbol "OnItemClickListener" in

 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

We have no idea why this error is occurring. Before this error we had one regarding Abstract class, but i think we fixed this.

Upvotes: 0

Views: 4355

Answers (1)

nandsito
nandsito

Reputation: 3852

The method name is incorrect. Try this:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent nextActivity = new Intent(UserArea.this, Artical_View.class);
        startActivity(nextActivity);
    }
});

Upvotes: 1

Related Questions