2016-01-20 45 views
0

單擊此項目時,我需要在我的listView上隱藏小圖標。 不幸的是,在我的應用程序中,當我點擊ListView中的任何項目時,總是隱藏第一個圖標。Android在我的列表中隱藏小圖標查看

我做錯了什麼?

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> listView, View view, int position, long id) { 

      Log.d(TAG, "onItemClick: position:" + position); 

      // Get cursor 
      Cursor cursor = (Cursor) listView.getItemAtPosition(position); 

      // Variables from database 
      String rowId = cursor.getString(cursor.getColumnIndexOrThrow("_id")); 
      String english = cursor.getString(cursor.getColumnIndexOrThrow("english")); 
      String speak = cursor.getString(cursor.getColumnIndexOrThrow("speak")); 


      // Set visibility THIS icon 
      ImageView imageLearned = (ImageView)findViewById(R.id.imageLearned); 
      imageLearned.setVisibility(View.GONE); 




      // Show varibles from database 
      Snackbar.make(view, english + " [" + speak + "]", Snackbar.LENGTH_LONG).setAction("Action", null).show(); 

     } 

    }); 
+0

這裏附加XML也請 –

回答

2

你需要指定當前視圖:
變化

ImageView imageLearned = (ImageView)findViewById(R.id.imageLearned); 

ImageView imageLearned = (ImageView)view.findViewById(R.id.imageLearned); 
+0

感謝名單!它解決了我的問題! – Karol