這讓我非常瘋狂,我不知道發生了什麼。 我有一個可點擊的RelativeLayout內的TextView的XML佈局。TextView not found
<RelativeLayout
android:id="@+id/bg_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@color/almost_black"
android:clickable="true"
android:onClick="goToBG"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Go To B.G."
android:textColor="@color/white"
android:textSize="20sp" />
<ImageView
android:id="@+id/bg_arrow"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-10dp"
android:src="@drawable/arrow_icon" />
<TextView
android:id="@+id/current_bg_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/bg_arrow"
android:text="3"
android:textColor="@color/holo_blue"
android:textSize="22sp" />
</RelativeLayout>
現在在我的代碼,我嘗試更新的TextView「current_bg_count」
private void updateBGCount(){
try{
RelativeLayout bgSection = (RelativeLayout) findViewById(R.id.bg_section);
TextView bgCountTV = (TextView) bgSection.getChildAt(2);
bgCountTV.setText(tempBG.size());
}
catch(Exception e){
e.printStackTrace();
Logger.d(TAG, "exception in updateBGCount");
}
}
這使得在哪裏我的setText雖然RelativeLayout的是沒有發現問題就行了ResourceNotFountException。即使當我嘗試找到它只是像這樣的ID:
TextView bgCountTV = (TextView) findViewById(R.id.current_bg_count)
bgCountTV.setText(tempBG.size());
它給出了同樣的錯誤。 佈局中的所有其他視圖都很容易找到並更新得很好。只有這一個TextView給我的問題。有誰知道問題是什麼?
您是否嘗試過清理你的項目? 「項目 - >清潔...」 – codeMagic
嘗試清理你的項目。 –
tempBG是指什麼?這是一個數組? – wyoskibum