2017-03-22 223 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); 
    } 
});