0
我試圖從xml文件動態地添加一些ProgressBar視圖到膨脹的佈局。我繼續得到的ClassCastExceptions運行下面的代碼時:檢索dyamily膨脹的佈局與
// === This is the part I'm having trouble with ===
ProgressBar v = (ProgressBar) mLayoutInflater.inflate(R.layout.dayprogressbar, ll);
ProgressBar p = (ProgressBar) mLayoutInflater.inflate(R.layout.dayprogressbar, ll);
下面的代碼是如何工作的,而不管型和無差錯運行,但我需要的意見,進度條工作。有沒有什麼辦法可以做到這一點沒有得到一個ClassCastException
/**
* Pulls the layout from R.layout.listview and creates a single list
* entry and returns it as a view to be put into the listview
*/
public View getView(int position, View convertView, ViewGroup parent) {
// the view to be returned
View itemLayoutView = convertView;
// if the view doesn't exist, create the layout from the inflator
if (itemLayoutView == null) {
LayoutInflater mLayoutInflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// use listview.xml
itemLayoutView = mLayoutInflater.inflate(R.layout.listview,
null);
LinearLayout ll = (LinearLayout) itemLayoutView.findViewById(R.id.List_Main_LinearLayout_ProgressBars);
// === This is the part I'm having trouble with ===
View v = mLayoutInflater.inflate(R.layout.dayprogressbar, ll);
View p = mLayoutInflater.inflate(R.layout.dayprogressbar, ll);
}
這裏是R.layout.dayprogressbar.xml我正在不斷膨脹:
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="50"
android:indeterminateOnly="false"
android:progressDrawable="@android:drawable/progress_horizontal"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:minHeight="1dip"
android:maxHeight="1dip"
android:max="100"
android:paddingLeft="1dp"
android:layout_weight="2"
/>
我不能undrstnd烏爾need.you要在佈局中添加進度或想要定製進度? – 2011-02-02 07:53:45
我已經膨脹了一個xml文件,但是我想向文件內的一個linearlayout添加2個進度條。這裏是我拉線性佈局的地方 LinearLayout ll =(LinearLayout)itemLayoutView.findViewById(R.id.List_Main_LinearLayout_ProgressBars); 我想將進度條添加到此佈局,然後更改條的進度。要更改條的進度,我需要使用2個充氣的dayprogressbar.xml對象作爲ProgressBar對象而不是View對象,所以我需要以某種方式進行投射或轉換。我想知道如何做到這一點,而不會例外:) – 2011-02-02 08:02:09