我在seekbarlist.xml的contentview中,需要获取seekbars.xml的布局。 我需要将布局发送到CustomSeekBar构造函数。下面,您可以看到我尝试将内容视图设置为一个布局,抓住它,然后切换到另一个。这不起作用b / c我必须扩展listactivity并且布局必须有一个id为“list”的项目。 seekbars.xml没有“列表”,它拥有它是没有意义的。 如何获得搜索栏的布局?
public class ColorsActivity extends ListActivity {
/** Called when the activity is first created. */
//Array Adapter that will hold our ArrayList and display the items on the ListView
SeekBarAdaptor seekBarAdaptor;
//List that will host our items and allow us to modify that array adapter
ArrayList<CustomSeekBar> seekBarArrayList=null;
// TextView myValueText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seekbars);
LinearLayout myLayout = (LinearLayout)findViewById(R.layout.seekbars);
setContentView(R.layout.seekbarlist);
//Initialize ListView
ListView lstTest= getListView();
//Initialize our ArrayList
seekBarArrayList = new ArrayList<CustomSeekBar>();
//Initialize our array adapter
seekBarAdaptor = new SeekBarAdaptor(ColorsActivity.this, R.layout.seekbars, seekBarArrayList);
CustomSeekBar red = new CustomSeekBar(this, myLayout, "red", 1);
//CustomSeekBar blue = new CustomSeekBar(this, "blue");
//CustomSeekBar green = new CustomSeekBar(this, "green");
//Set the above adapter as the adapter of choice for our list
lstTest.setAdapter(seekBarAdaptor);
seekBarArrayList.add(red);
//seekBarArrayList.add(blue);
//seekBarArrayList.add(green);
Amarino.connect(this, "00:11:11:21:05:53");
}
}
答案 0 :(得分:3)
您需要使用LayoutInflater。
LayoutInflater.from(this).inflate(R.layout.seekbars, null);
您可以将null传递给ViewGroup参数。
在此处阅读有关LayoutInflater的更多信息 http://developer.android.com/reference/android/view/LayoutInflater.html