我有一个问题,我不想像加载当前活动一样
Activity currentActivity = getCurrentActivity();
我想加载另一个活动...
TabActivity MainTabView = (TabActivity) getParent();
TabHost tabhost = MainTabView.getTabHost();
tabhost.setCurrentTab(1); // Artikelliste
Activity currentActivity = MainActivity; // what i want to load is called MainActivity (doesn't work)
((MainActivity) currentActivity).reload("22"); // Call the public function of MainActivity.
我想重新加载选项卡活动 1 中的内容。我切换到选项卡并重新加载列表视图控件中的内容。
我是android开发的新手。我希望很清楚我想要什么:-)
MainActivity 的重新加载功能,我不知道这是否适用于我。
public void reload(String strCatID) {
// Artikeldatenbank laden als Thread
downloadJTLShopArtikeldatenbank("http://www.xyz.com/connector/jtl-shop-connector.php?modus=artikelliste&iCatID="+ strCatID);
// Artikel öffnen im Shop
lvwArtikel = (ListView) findViewById(R.id.lvwArtikelansicht);
lvwArtikel.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
View grid;
if (view == null) {
grid = null;
} else {
grid = view;
}
// Abrufen aus dem aktiven Listview Eintrag (ArtikelID)
TextView txtArtikelID = (TextView) grid.findViewById(R.id.txtArtikelID);
// Neues Intent öffnen und die aktuelle Kategorie ID übergeben
Intent i = new Intent(MainActivity.this, MainItemsDetail.class);
i.putExtra("iArtikelID", txtArtikelID.getText());
/* tabHost.addTab(tabHost.newTabSpec("tab-2")
.setIndicator("Artikel")
.setContent(i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.setContent(i)); */
//.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
startActivityForResult(i, 0);
}
});
}
带有我需要的选项卡的 MainTabView
final TabHost tabHost = getTabHost();
// Kategorieliste
TabHost.TabSpec ts1 = tabHost.newTabSpec("tab-1");
ts1.setIndicator("Kategorie");
Intent intent1 = new Intent(MainTabView.this,MainCategory.class);
//ts1.setContent(intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
ts1.setContent(intent1);
tabHost.addTab(ts1);
//progressDialog = ProgressDialog.show(MainTabView.this, "",
// "Kategorien werden geladen");
// Artikelliste
TabHost.TabSpec ts2 = tabHost.newTabSpec("tab-2");
ts2.setIndicator("Artikel");
Intent intent2 = new Intent(MainTabView.this,MainActivity.class);
//ts2.setContent(intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
ts2.setContent(intent2);
tabHost.addTab(ts2);
//progressDialog = ProgressDialog.show(MainTabView.this, "",
// "Artikel werden geladen");
// Warenkorb hinzufügen
TabHost.TabSpec ts3 = tabHost.newTabSpec("tab-3");
ts3.setIndicator("Warenkorb");
Intent intent3 = new Intent(MainTabView.this,MainCart.class);
//ts3.setContent(intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
ts3.setContent(intent3);
tabHost.addTab(ts3);
//progressDialog = ProgressDialog.show(MainTabView.this, "",
// "Artikel werden geladen");
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
Activity currentActivity = getCurrentActivity();
if (currentActivity instanceof MainActivity) {
((MainActivity) currentActivity).reload("22");
}
}
});
}
对代码中的德语注释感到抱歉。
我真正想要的是从 MainCategoryTab 切换到 MainActivityTab(项目列表),我想对可扩展列表视图中的 OnClick 事件做出反应。我想切换到 MainActivity 并重新加载项目列表。