我正在尝试单击位于我的 MainActivity 中的按钮并使用全息图库打开带有饼图的活动。问题是全息图样本由片段构成,没有活动。这是饼片段:已编辑
public class grafico extends Activity {
public View onCreate(Bundle savedInstanceState, LayoutInflater inflater, ViewGroup container) {
final View v = inflater.inflate(R.layout.piegrafico, container, false);
PieGraph pg = (PieGraph)v.findViewById(R.id.piegraph);
PieSlice slice = new PieSlice();
slice.setColor(Color.parseColor("#99CC00"));
slice.setValue(2);
pg.addSlice(slice);
slice = new PieSlice();
slice.setColor(Color.parseColor("#FFBB33"));
slice.setValue(10);
pg.addSlice(slice);
slice = new PieSlice();
slice.setColor(Color.parseColor("#AA66CC"));
slice.setValue(2);
pg.addSlice(slice);
pg.setOnSliceClickedListener(new OnSliceClickedListener(){
@Override
public void onClick(int index) {
}
});
return v;
}
}
和我在 MainActivity 中的按钮:
public void graph(View view)
{
Intent intent = new Intent(MainActivity.this, grafico.class);
startActivity(intent);
}
main.xml 中的按钮:
<Button
android:id="@+id/grafico"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="grafico"
android:text="grafico" />
logcat 说:
java.lang.IllegalStateException: Could not find a method grafico(View) in the activity
---
---
Caused by: java.lang.NoSuchMethodException: grafico [class android.view.View]
所以我认为问题在于 grafico 活动是一个片段。我该如何解决?