TimePicker、栄養のリストとボタンを備えたスピナーを備えたアクティビティがあります。ボタンを押すと、Spinner をビューに動的に追加したいと考えています。
これは私のボタンです:
<Button
android:layout_marginTop="350dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Aggiungi un altro alimento"
android:id="@+id/button"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:onClick="addAnotherAliment"/>
そして、これは onClick イベントの後に呼び出される関連メソッドです
public void addAnotherAliment(View view) {
Spinner alimentSpinner = new Spinner(this);
ArrayAdapter<String> alimentAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.aliments)
);
alimentSpinner.setAdapter(alimentAdapter);
LinearLayout containerLayout = (LinearLayout) findViewById(R.id.container);
containerLayout.addView(alimentSpinner);
}
しかし、「残念ながら、あなたのアプリは停止しました」と表示されます。どうしたの?
これはアクティビティ全体です。
public class SecondActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
populateFirstSpinner();
}
private void populateFirstSpinner() {
setContentView(R.layout.activity_second);
Spinner spinnerAliments = (Spinner) findViewById(R.id.alimenti);
ArrayAdapter<String> spinnerCountAliments = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, getResources().getStringArray(R.array.aliments));
spinnerAliments.setAdapter(spinnerCountAliments);
}
public void addAnotherAliment(View view) {
Spinner alimentSpinner = new Spinner(this);
ArrayAdapter<String> alimentAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_dropdown_item,
getResources().getStringArray(R.array.aliments)
);
alimentSpinner.setAdapter(alimentAdapter);
LinearLayout containerLayout = (LinearLayout)findViewById(R.id.container_registration);
containerLayout.addView(alimentSpinner);
}
}
Logcat は次のように述べています。
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 0 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 1 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 2 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 3 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 4 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 5 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 6 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 7 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 8 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 9 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 10 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 11 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 12 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 13 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 14 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 15 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 16 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 17 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 18 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 19 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 20 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 21 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 22 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 23 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 24 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 25 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 26 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 27 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 28 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 29 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 30 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 31 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 32 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-05 18:05:21.002 1113-1113/com.android.defcontainer W/dalvikvm﹕ PR_CAPBSET_DROP 33 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.