J'essaie d'ajouter dynamiquement des vues ProgressBar à une mise en page gonflée à partir d'un fichier xml. Je continue à obtenir ClassCastExceptions lors de l'exécution du code suivant:Récupérer des mises en page gonflées de façon dynamique pour travailler avec
// === 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);
Le code ci-dessous comment cela fonctionne sans les moulages et fonctionne sans erreur, mais je dois travailler avec les vues comme une barre de progression. Est-il possible que je peux le faire sans obtenir un 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);
}
Voici R.layout.dayprogressbar.xml que je Gonflage:
<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"
/>
i cant undrstnd ur need.you voulez ajouter dans la mise en page ou progressbar voulez progressbar personnalisée? –
J'ai gonflé un fichier XML, mais je veux ajouter 2 barres de progression à une linearlayout dans le fichier. Voici où je tire la distribution linéaire LinearLayout ll = (LinearLayout) itemLayoutView.findViewById (R.id.List_Main_LinearLayout_ProgressBars); et je veux ajouter les barres de progression à cette mise en page, puis modifier la progression des barres. Pour modifier la progression des barres, j'ai besoin de travailler avec les 2 objets dayprogressbar.xml gonflés car les objets ProgressBar ne sont pas des objets View, donc j'ai besoin de les convertir ou de les convertir d'une manière ou d'une autre. Je voudrais savoir comment le faire sans avoir des exceptions :) –