2017-03-22 7 views
-2

So entwickeln ich und mein Team eine App für Nachrichtenartikel. Die Idee des Skripts besteht darin, einen Namen eines Artikels aus einer Top-20-Liste antippen zu können, um zum eigentlichen Artikel zu gelangen. So einfach das auch sein mag, wir haben Fehler mit diesem Code bekommen.Das Symbol "OnItemClickListener" kann nicht aufgelöst werden.

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

     }); 







} 

}

Wir halten immer Symbol "OnItemClickListener" in

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

Wir haben keine Ahnung, warum dieser Fehler auftritt, kann nicht aufgelöst werden. Vor diesem Fehler hatten wir eine Abstraktionsklasse, aber ich denke, wir haben das behoben.

+0

Wo die Schnittstelle, die der Hörer definieren ist die Schnittstelle behaviour..Implement .. –

+0

Wenden javadocs ... https://developer.android.com/reference/android/widget/AdapterView. OnItemClickListener.html – pringi

Antwort

1

Der Methodenname ist falsch. Versuchen Sie folgendes:

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