0
我動態添加一些錶行到tableLayout並添加onClickListener每一行向但當我removeAllViews,由於某種原因,它擺脫了聽衆太....刪除所有瀏覽擺脫的OnClickListener
這裏是我的添加數據代碼:
private void addTickerToTable(String ticker, String last, String chg, String pchg, String time){
rowId++;
int theColor=Color.WHITE;
int rowColor=0;
float theSize=13f;
lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row= new TableRow(this);
row.setPadding(0, 5, 0, 5);
if(rowOdd==0){row.setBackgroundColor(Color.parseColor("#343434"));rowColor=Color.parseColor("#343434");}
if(rowOdd==1){row.setBackgroundColor(Color.BLACK);rowOdd=-1;rowColor=Color.BLACK;}
rowOdd++;
row.setLayoutParams(lp);
tv0 = new TextView(this);
tv0.setTextColor(Color.parseColor("#3A54A7"));
tv0.setTextSize(theSize);
tv1 = new TextView(this);
tv1.setTextColor(theColor);
tv1.setTextSize(theSize);
tv2 = new TextView(this);
tv2.setTextSize(theSize);
tv3 = new TextView(this);
tv3.setTextSize(theSize);
tv0.setText(ticker);
tv0.setLayoutParams(params);
row.addView(tv0);
tv1.setText(last);
tv1.setLayoutParams(params);
row.addView(tv1);
tv2.setText(chg);
tv2.setLayoutParams(params);
row.addView(tv2);
tv3.setText(pchg);
tv3.setLayoutParams(params);
row.addView(tv3);
ll.addView(row,rowCount);
row.setId(rowId);
row.setOnClickListener(this);
row.setOnLongClickListener(this);
row.startAnimation(anim2);
rowCount++;
}
然後我有一個簡單的重置數據 -
ll.removeAllViews();
rowCount=0;
rowOdd=0;
rowId=0;
它運行一個單獨的方法完美的第一時間 - 一切爲c可舔等...但只要你刷新或運行重置代碼,突然onClickListeners不工作...