我的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
方法。
答案 0 :(得分:0)
Intent myIntent = new Intent(MainActivity.this, NextActivity.class);
MainActivity.this.startActivity(myIntent);
您可能还希望在activity_main.xml中实现UI元素以触发传输。也许你应该在xml中添加一个按钮并使用android:onCLick。
即
{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);
}
答案 1 :(得分:0)
要从另一个活动(而不是主要活动)调用活动,您必须分离上下文:
{latitude: resp.coords.latitude, longitude: resp.coords.longitude}