我想动态添加微调器到RelativeLayout,但我遇到了问题。 这是我的代码。动态添加微调器到RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/Relativ"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
</RelativeLayout>
而且在我的课:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.Relativ);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,1);
adapter.add("1");
adapter.add("2");
adapter.add("3");
adapter.add("4");
adapter.add("5");
Spinner list = new Spinner(this);
list.setAdapter(adapter);
rl.addView(list);
}
但开不运行。我想知道我的代码中有什么问题,以及如何修复它。 我已经在RelativeLayout.addView中使用RelativeLayout参数进行了尝试,并且它不运行。 谢谢。
你说的 “不运行” 是什么意思?不编译?崩溃? – 2014-10-07 22:12:15
应用程序崩溃 – guillocrack 2014-10-07 22:21:39
然后,您应该在此处发布logcat转储,但只能在您自己阅读之后。 – 2014-10-07 22:22:40