Android在我的listView上隐藏小图标

时间:2016-01-20 14:42:08

标签: android listview

点击此项目时,我需要在listView上隐藏小图标。 不幸的是,在我的应用程序中,当我单击ListView中的任何项目时,始终隐藏第一个图标。

我做错了什么?

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

        }

    });

1 个答案:

答案 0 :(得分:2)

您需要指定当前视图:
变化

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

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