2017-03-22 11 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

.. –

+0

はjavadocを... https://developer.android.com/reference/android/widget/AdapterViewを参照してください。 OnItemClickListener.html – pringi

答えて

1

メソッド名が正しくありません。これを試してみてください:リスナーを定義するインタフェースはインタフェースをbehaviour..Implementさ

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); 
    } 
}); 
関連する問題