我做了一個方法來創建具有某些CSS樣式的textviews,但我把代碼放在一個類中,它突然停止工作。我首先得到了「this」,因爲它在主類中,但現在它在一個子類中,「this」在那裏不起作用,所以我刪除了它,現在我得到了一個不同的錯誤,我不知道如何修復。構造函數TextView()未定義
public class textviewscreate {
public void textviewToevoegen(RelativeLayout relativeLayout) {
RelativeLayout.LayoutParams relativeLayoutParams;
String[] naam = {"Bouw onderdeel", "Kapconstructie","Kapconstructieve bevesiging","Doorbuiging","Vochtinwerking","Dakconstructie","Constructieve bevesiging","Doorbuiging","Vochtinwerking","Waterkerende lagen","Waterdichtheid (folie)laag","Lekwaterafvoerend vermogen","Detaillering aan dakvoet","Thermischeisolatie","Bevestiging","Aansluitdetails","Isolerend vermogen","Dakpannen en vorsten","Conditie dakpannen en vorsten","Breukschade","Vorstschade","Afschilfering","Aangroei algen en mos"};
TextView[] textView = new TextView[22];
//1st TextView
textView[0] = new TextView(); //This gives an error, first was new TextView(this);
relativeLayoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
textView[0].setId(1); // changed id from 0 to 1
textView[0].setText(naam[0].toUpperCase());
relativeLayout.addView(textView[0], relativeLayoutParams);
relativeLayoutParams.setMargins(24, 39, 0, 0);
// All othet Textviews
for (int i = 1; i < textView.length; i++) {
relativeLayoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
relativeLayoutParams.addRule(RelativeLayout.BELOW,
textView[i-1].getId());
relativeLayoutParams.addRule(RelativeLayout.ALIGN_LEFT,
textView[i-1].getId()); // added top alignment rule
textView[i] = new TextView(); //Also an error firstly new TextView(this);
textView[i].setText(naam[i]);
textView[i].setId(i+1);
relativeLayout.addView(textView[i], relativeLayoutParams);
}
}
}
給那個投了倒票的人..會不會很好評論爲什麼投票棄權 – user2450263 2014-10-22 09:47:37