I have such a task: there is a list. When you click on any item, scrolling the list and clicking is blocked. In addition to this, it is necessary for me that all items except for the click become half transparent. And, when the clicked item performs an action, all items have lost their transparency. I do this:
for(int x=0; x<lv.getCount(); ;x++){ lv_inspiration.getChildAt(x).setAlpha(0.5f); }
But the game crashed. I added the code for output to the log and realized that the case was cut off in the last items
Attempt to invoke virtual method 'void android.view.View.setAlpha(float)' on a null object refere
I also logged the number of items in the log, it was 2 times less than in reality (the number is always nine, it was 7). What to do? Aytemov 9, and the eighth and ninth seemed to be gone. Do not offer to put transparency on the list, because you need exactly the effect of transparency on all items except the clicked. Help where to dig? I have my own adapter, maybe there is something?
Here is the listener:
lv_inspiration.setOnItemClickListener(new OnItemClickListener(){ ProgressBar pb; @Override public void onItemClick(AdapterView<?> p1, View p2, final int position, long p4) { for(int x=0; x<lv_inspiration.getCount(); x++){ if(x!=position) lv_inspiration.getChildAt(x).setAlpha(0.5f); } lv_inspiration.setEnabled(false); lv_inspiration.smoothScrollToPosition(position); pb = (ProgressBar)p2.findViewById(R.id.progress_bar_item); pb.setProgress(0); cdt = new CountDownTimer(50000, 200) { @Override public void onTick(long millisUntilFinished) { if(pb.getProgress()!=100) pb.setProgress(pb.getProgress()+1); else onFinish(); } @Override public void onFinish() { cdt.cancel(); for(int x=0; x<lv_inspiration.getCount(); x++){ lv_inspiration.getChildAt(x).setAlpha(1f); } lv_inspiration.setEnabled(true); } }.start(); }})
View
from themView
- pavlofff