我不明白为什么我的代码无法正常工作?
我总是有一个类,必须将其声明为抽象或实现抽象方法:
public class MainActivity extends AppCompatActivity implements MyRecyclerViewAdapter.ItemClickListener {
MyRecyclerViewAdapter adapter;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
return true;
case R.id.navigation_public:
return true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view);
mTextMessage = findViewById(R.id.message);
navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
ArrayList<String> mImageUrls = new ArrayList<>();
ArrayList<String> mNames = new ArrayList<>();
mImageUrls.add("https://c1.staticflickr.com/5/4636/25316407448_de5fbf183d_o.jpg");
mNames.add("Havasu Falls");
mImageUrls.add("https://i.redd.it/tpsnoz5bzo501.jpg");
mNames.add("Trondheim");
// set up the RecyclerView
RecyclerView recyclerView = findViewById(R.id.recycler_public);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new MyRecyclerViewAdapter(this, mImageUrls);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
}
}
答案 0 :(得分:0)
我找到了答案...我忘了这个:
@Override
public void onItemClick(View view, int position) {
Toast.makeText(this, "You clicked " + adapter.getItem(position) + " on row number " + position, Toast.LENGTH_SHORT).show();
}
对不起...