0

我的 MainActivity 课程是:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    UserInterface_Main  UIMain = new UserInterface_Main();
    setContentView(R.layout.activity_main);
    UIMain.ExpendableListView();
}   

另一个 Activity 类是:

public class UserInterface_Main extends Activity{

ExpandableListView exv;

public void ExpendableListView()
{

    Context context = getApplicationContext();
    exv=(ExpandableListView)findViewById(R.id.elv1);
    exv.setAdapter(new MAdapter(context));
}

现在告诉我如何从类中调用ExpendableListView()方法。MainActivity

4

2 回答 2

0
Intent myIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(myIntent);

您可能还想在 activity_main.xml 中实现一个 UI 元素来触发传输。也许您应该添加一个按钮并在 xml 中使用 android:onCLick。

IE。

{xml}

<Button
       android:id="@+id/button2"
       android:layout_width="200dp"
       android:layout_height="100dp"
       android:text="coolbutton" 
       android:onClick="blah"  />

{MainActivity.java}

public void blah(View view){
    Intent myIntent = new Intent(MainActivity.this, NextActivity.class);
    MainActivity.this.startActivity(myIntent);
}
于 2013-04-20T18:33:16.813 回答
0

要从另一个活动(不是主要活动)调用活动,您必须指定上下文:

                Intent i = new Intent(getApplicationContext(), secondActivity.class);
                getApplicationContext().startActivity(i);
于 2017-04-01T21:55:06.533 回答