2017-03-22 147 views
-2

所以我和我的团队正在开发一个关于新闻文章的应用程序。脚本的想法是能够从前20名单中挖掘一篇文章的名称,以便获得实际的文章。尽可能容易,我们已经遇到了这个代码的错误。无法解析符号“OnItemClickListener”

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); 
      } 

     }); 







} 

}

我们不断收到无法解析符号 “OnItemClickListener” 在

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

我们不知道为什么这个错误发生。在这个错误之前,我们有一个关于抽象类的问题,但我认为我们解决了这个问题

+0

哪里是定义监听behaviour..Implement的接口的接口.. –

+0

参考JavaDoc ... https://developer.android.com/reference/android/widget/AdapterView。 OnItemClickListener.html – pringi

回答

1

方法名称不正确。试试这个:

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); 
    } 
});