訪問充氣的RatingBar我有一個異步的任務,檢查用戶是否有某一個項目,通過檢查數據庫。如果他們有一個項目,然後我膨脹一個評級欄,如果沒有我膨脹一個按鈕,以便他們可以添加該項目。麻煩的Android
我誇大評級酒吧與擴展的AsyncTask的類:
//inflate star rater
LayoutInflater mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout addButton = (LinearLayout)((Activity) c).findViewById(R.id.addBeerLayout);
addButton.addView(mInflater.inflate(R.layout.addrate_layout, null));
addListenerOnRatingBar();
的問題是增加它會調用另一個異步任務的等級保存到外部數據庫偵聽器時。
我addListenerOnRatingBar()方法如下所示:
public void addListenerOnRatingBar() {
RatingBar ratingBar = (RatingBar) findViewById(R.id.beerRatingBar);
//if rating value is changed,
//display the current rating value in the result (textview) automatically
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
//next async task to update online database
}
});
}
的findviewbyid給出了日食此錯誤:
The method findViewById(int) is undefined for the type CheckBeerJSON
我以爲是因爲它沒有延伸活動,所以我很困惑的如何正確實施這一點。
充氣ratebar XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RatingBar
android:id="@+id/beerRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:rating="0" />
</LinearLayout>
難道你看從膨脹的觀點的評價吧? 'inflatedviewlayout.findViewById(INT)' – kabuto178
不知道你的意思。 addlistener函數在我的異步任務 – Mike