0

I'm creating a custom component for an Android App (exactly a volume fader for an audio mixer). It works fine.

What I want is to load several instances of this component at Run-Time. I tried with this:

LinearLayout layout = (LinearLayout)findViewById(R.id.mixerContainer) //This layout
for(int i=0;i<8;i++){
  LayoutInflater l = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View v = l.inflate(R.Layout.MyVolumeFader, null);
  layout.add(v);
}

This adds the view correctly, but doesn't attach all the logic of my component (that is contained in MyVolumeFader class).

How can I solve this problem?

--

The code looks like:

MyVolumeFader.java

public class MyVolumeFader extends RelativeLayout{
 [...]

 private VerticalSeekBar volumeBar;

 [...]

 ->volumeBar handling<-
}

MyVolumeFader.xml

<RelativeLayout...
Some TextViews, Buttons and a VerticalSeekBar are here...

Thank you.

rPulvi
  • 946
  • 8
  • 33
  • SOLVED. The right way is: `LinearLayout l = (LinearLayout)findViewById(R.id.containerLayout); MyVolumeFader f = new MyVolumeFader(this, null); l.addView(f);` Remember to use "this" when calling CustomView constructor. – rPulvi Feb 04 '13 at 10:14

1 Answers1

0

You may consider using windowmanager and its' addview method to solve your provlem like this.

mWindowManager.addView(new ChartTools(this, a, list, "业务统计").getChart(),
        ParamTools.getChartParams());
user1198331
  • 139
  • 2
  • 3
  • 10