How to highlight row in ListView in Android?

后端 未结 8 1489
天涯浪人
天涯浪人 2020-11-27 06:05

I need to highlight a row in a ListView that was selected (to show the user what he chose), so, it\'s not the one that is going to be chosen, it\'s the one he c

8条回答
  •  执念已碎
    2020-11-27 06:27

    The SIMPLEST of all

    View updatedview=null;
    
    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {
    
        //these two lines of code means that only one item can be selected at a time
        if(updatedview != null)
            updatedview.setBackgroundColor(Color.TRANSPARENT);
        updatedview=view;
    
        Toast.makeText(getApplicationContext(), " " + str[position],Toast.LENGTH_LONG).show();
        view.setBackgroundColor(Color.CYAN);
    }
    

提交回复
热议问题