使用按钮添加标签的错误在哪里?

时间:2018-06-22 17:28:05

标签: android-emulator android-tabs android-tablelayout android-tabactivity android-tabbed-activity

我想添加一个带有按钮的新标签页。我没有遇到错误,但我的应用已在模拟器中停止。我的错误在哪里?谢谢您的全力帮助。注意:我的英语不好,抱歉。如果您没有关于主题的代码或想法,请不要编写pls。

private Button Add_Tab_Button;
int counter=0,counter2;
String[] Strings={
    "Section "+counter,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Add_Tab_Button=(Button) findViewById(R.id.Add_Tab_Button);
    final String[] Strings2 = new String[Strings.length+1];

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    Add_Tab_Button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int array_size=Strings.length+1;
            for(; counter <array_size ; counter++)
Strings2[counter] = Strings[counter];
counter2=counter+1;
Strings2[counter2]="Section "+counter2;
        }
    });
    // Setup spinner
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    spinner.setAdapter(new MyAdapter(
            toolbar.getContext(),
            Strings2));

这是我的事件日志:

19:51   Executing tasks: [:app:assembleDebug]
19:51   Gradle build finished in 13s 257ms
19:52   Emulator: Process finished with exit code 0

0 个答案:

没有答案