我是android的初学者。我试图在我的广播组中实现一个on checked change listener,但它导致我的应用程序崩溃。它的工作正常,没有听众。代码如下:
package com.vogella.android.testapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
final RadioGroup layoutChoice=(RadioGroup)findViewById(R.id.orientation);
layoutChoice.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group,int checkedId)
{
switch(checkedId)
{
case R.id.horizontal:
group.setOrientation(LinearLayout.HORIZONTAL);
break;
case R.id.vertical:
group.setOrientation(LinearLayout.VERTICAL);
break;
}
}
});
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick (View view) {
EditText text=(EditText)findViewById(R.id.main_input);
String input=text.getText().toString();
Toast.makeText(this,input,Toast.LENGTH_LONG).show();
}
}