我有一个应用程序,根据选择的单选按钮创建一个新的活动点击。它适用于选项“3”,但与任何其他选项崩溃。
这是我的课程多项式:
public class Polynomials extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View polyView = inflater.inflate(R.layout.fragment_poly, container, false);
//layout
RadioGroup rbg = (RadioGroup) polyView.findViewById(R.id.rBGPolyn);
Button next = (Button) polyView.findViewById(R.id.btnNxt);
final TextView checked = (TextView) polyView.findViewById(R.id.testpoly);
RadioButton but3 = (RadioButton) polyView.findViewById(R.id.rb3);
RadioButton but4 = (RadioButton) polyView.findViewById(R.id.rb4);
RadioButton but5 = (RadioButton) polyView.findViewById(R.id.rb5);
RadioButton but6 = (RadioButton) polyView.findViewById(R.id.rb6);
RadioButton but7 = (RadioButton) polyView.findViewById(R.id.rb7);
//RadioButton but8 = (RadioButton) polyView.findViewById(R.id.radioButton6);
// reference to radio group
final RadioGroup g = (RadioGroup)polyView.findViewById(R.id.rBGPolyn);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int selected = g.getCheckedRadioButtonId();
RadioButton clickedButton=(RadioButton)polyView.findViewById(selected);
checked.setText(""+clickedButton.getText());
if(checked.getText().equals("3")){
b3clicked();
}
else {
if (checked.getText().equals("4")) {
b4clicked();
}
else {
if (checked.getText().equals("5")) {
b5clicked();
}
else {
if (checked.getText().equals("6")) {
b6clicked();
}
else {
if (checked.getText().equals("7")) {
b7clicked();
}
}
}
}
}
}
});
return polyView;
}
public void b3clicked(){
Intent intent= new Intent(Polynomials.this.getActivity(), poly3.class);
startActivity(intent);
}
public void b4clicked(){
Intent intent= new Intent(Polynomials.this.getActivity(), poly4.class);
startActivity(intent);
}
public void b5clicked(){
Intent intent= new Intent(Polynomials.this.getActivity(), poly5.class);
startActivity(intent);
}
public void b6clicked(){
Intent intent= new Intent(Polynomials.this.getActivity(), poly6.class);
startActivity(intent);
}
public void b7clicked(){
Intent intent= new Intent(Polynomials.this.getActivity(), poly7.class);
startActivity(intent);
}
}
功能b3clicked工作正常但其他导致应用程序崩溃。这是类poly3:
public class poly3 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_poly3);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_poly3, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
对于比较类,函数b4clicked的poly4不起作用:
public class poly4 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_poly4);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_poly4, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是activity_poly3:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.michniewicz.jan.mathcalcalpha.adapter.poly3">
<TextView android:text="3 terms" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
这是activity_poly4:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.michniewicz.jan.mathcalcalpha.adapter.poly4">
<TextView android:text="4 terms" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
菜单poly 3:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.michniewicz.jan.mathcalcalpha.adapter.poly3">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
菜单poly 4:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.michniewicz.jan.mathcalcalpha.adapter.poly4">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
我刚刚复制了poly 3类或活动或菜单中的所有内容,并粘贴到下一个仅更改对应于类或活动的数字的内容。 为什么我的功能b4cliked不起作用?