0

I have layout.xml associated with activity1 which have various components including linearlayout, I have also stored one progressbar in progress.xml and on run time using LayoutInflater I am retrieving the progressbar and adding it to linearlayout of layout.xml

My progress.xml :

Case 1 :

<?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" >

<ProgressBar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="100dp"
    android:layout_height="102dp"
    android:layout_gravity="center"
    android:indeterminate="false"
    android:max="100"
    android:progress="100"
    android:progressDrawable="@drawable/custom_bar"
    />

</LinearLayout>

Case 2 :

<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="100dp"
    android:layout_height="102dp"
    android:layout_gravity="center"
    android:indeterminate="false"
    android:max="100"
    android:progress="100"
    android:progressDrawable="@drawable/custom_bar"
    />

When I am using xml in case1 I can successfully add progress bar at run time but when I am using case2 xml I cant add progress bar at run time... please help..

I am using following code to add progressbar from case2 xml :

LinearLayout ll = (LinearLayout) findViewById(R.id.container_linear_layout);

    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View otherView = layoutInflater.inflate(R.layout.progress, null);
    pb = (ProgressBar) otherView.findViewById(R.id.progressBar1);
    ll.addView(pb);    
DCoder
  • 3,486
  • 7
  • 36
  • 68
  • Try `ll.addView(otherView );` in stead of `ll.addView(pb);` – Spring Breaker Mar 14 '14 at 11:48
  • @Spring Breaker: good tips.. and also clear or remove the child view before adding if it already exists otherwise it throws exception.. – Ranjit Mar 14 '14 at 11:51
  • Spring Breaker I have also tried that but its not working.... And In case two there are no parent view I guess... In first case I do have used removeView() method.... – DCoder Mar 15 '14 at 16:14
  • Ranjit Pati sorry for late reply... I want to use progress bar defined in xml shown in case 2... – DCoder Mar 15 '14 at 16:16

0 Answers0