0
我想眨眼listView自定義行儘管我正在尋找淡出淡出動畫列表視圖行,但在下面的代碼中,我只是改變圖像後一秒,並有設置問題啓動和訪問listView getViews之外的背景。我正在使用Activity,listView是該活動中的一個組件。從自定義行動畫(閃爍)ListView
請指點如何訪問列表視圖的項目我BaseAdapter以外的自定義方法
public class MyView extends Activity implements {
private Timer activeCallBlinker;
MyListAdapter mActiveAdapter;
private class MyListAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private LayoutInflater inflater = null;
ViewHolder viewHolder = null;
public MyListAdapter(Activity act,
ArrayList<HashMap<String, String>> dta) {
activity = act;
data = dta;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
View view = null;
if (convertView == null) {
view = inflater.inflate(R.layout.my_listitem, null);
viewHolder = new ViewHolder();
viewHolder.cellBgImg = (ImageView) view.findViewById(R.id.cellBgImage); /// Works fine and setting
view.setTag(viewHolder);
} else {
view = convertView;
}
viewHolder = (ViewHolder) view.getTag();
viewHolder.cellBgImg.setImageResource(R.drawable.stripe_flash);
return view;
}
}
public void populateAndBlink() {
mActiveAdapter = new MyListAdapter(ActiveCallView.this, calledPartyArr);
AnimationAdapter animAdapter = new SwingBottomInAnimationAdapter(mActiveAdapter);
animAdapter.setAbsListView(getListView());
lvActiveCall.setAdapter(animAdapter);
//// After successful population with animation
I am looking to blink it with Fade in Fade out but I can't find a good way so just changing images of background for my listadapter items
activeCallBlinker = new Timer();
startActiveTimer();
}
public void startActiveTimer(){
final int wantedPosition = globalRowIndex;
final Handler handler = new Handler();
activeCallBlinker.scheduleAtFixedRate (new TimerTask(){
public void run(){
handler.post (new Runnable(){
public void run(){
runOnUiThread(new Runnable() // start actions in UI thread
{
@Override
public void run()
{
View cellView = mActiveAdapter.getView(wantedPosition, null,getListView());
//ViewHolder viewHolder = (ViewHolder) cellView.getTag();
ViewHolder viewHolder = new ViewHolder();
viewHolder.cellBgImg = (ImageView)cellView.findViewById(R.id.cellBgImage);
viewHolder.timerLbl = (TextView)cellView.findViewById(R.id.timerLbl);
if(viewHolder.timerLbl.getVisibility() == View.VISIBLE)
viewHolder.timerLbl.setVisibility(View.INVISIBLE); //// Unable to set InVisibility
else
viewHolder.timerLbl.setVisibility(View.VISIBLE); //// Unable to set Visibility
String resName = getResourceNameFromClassByID(R.drawable.class, R.drawable.stripe);
Log.d("Resource Name", resName);
final Drawable d1 = getResources().getDrawable(R.drawable.stripe);
final Drawable d2 = getResources().getDrawable(R.drawable.strip_header);
if (viewHolder.cellBgImg.getDrawable().equals(d1)) { //// Unable to check Drawable image for setting up background only else is called
Log.d("Resource Name", d1.toString());
viewHolder.cellBgImg.setImageResource(R.drawable.stripe_flash); //// Unable to change image of backkground
} else {
Log.d("Resource Name", d2.toString());
viewHolder.cellBgImg.setImageResource(R.drawable.stripe); //// Unable to change image of backkground
}
}
});
}
});
}
}, 0, 1000);
}
public ListView getListView() {
return lvActiveCall;
}
}
請參閱listView.getFirstVisiblePosition和getLastVisiblePosition – pskink