서버에서 데이터를 다운로드하는 응용 프로그램을 만드는 데 문제가 있습니다. 사용자가 탭 호스트 내에서 탭을 클릭하면 일부 데이터를 다운로드합니다. 탭이 가리키는 다음 활동은 데이터를 사용하여 목록보기를 채우는 개념입니다. 탭에 대해 onClickListener를 사용하려고했지만 작동하지 않는 것 같습니다. 나는 지금까지 가지고있는 것을 첨부하고있다. 사용자가 TAB_NAME_2 레이블이 붙은 탭을 클릭하면 performGetClasses() 메서드를 호출하고 싶습니다.Tab 도움말 OnClickListeners android
미리 감사드립니다.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
FileInputStream fis = openFileInput("token");
try {
fis.read(tokenInt);
token = new String(tokenInt);
fis.close();
} catch (IOException e) {
}
} catch (FileNotFoundException e) {
}
//TODO: Add code to send the token as a put extra to each tab, rather than retrieving in each separate activity.
setContentView(R.layout.home_screen);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Do the same for the other tabs
intent = new Intent().setClass(this, HomePage.class);
spec = tabHost.newTabSpec("TAB_NAME_1").setIndicator("Home",res.getDrawable(R.layout.ic_tab_home)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ClassesPage.class);
spec = tabHost.newTabSpec("TAB_NAME_2").setIndicator("Classes",res.getDrawable(R.layout.ic_tab_classes)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SearchPage.class);
spec = tabHost.newTabSpec("TAB_NAME_3").setIndicator("Search",res.getDrawable(R.layout.ic_tab_search)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MessagesPage.class);
spec = tabHost.newTabSpec("TAB_NAME_4").setIndicator("Messages",res.getDrawable(R.layout.ic_tab_messages)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, AccountPage.class);
spec = tabHost.newTabSpec("TAB_NAME_5").setIndicator("Account",res.getDrawable(R.layout.ic_tab_account)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
public void performGetClasses(String token){
progressDialog = ProgressDialog.show(HomeScreen.this,
"Please wait...", "Retrieving data...", true, true);
if (!(token == null)) {
PerformClassesTask task = new PerformClassesTask();
task.execute(token);
progressDialog.setOnCancelListener(new CancelTaskOnCancelListener(task));
}
}
탭을 전혀 사용하지 않아야하는 것처럼 들립니다. 탭은 다른 탭에 의존해서는 안됩니다. 이는 거의 확실하게 설계를 재고해야 함을 의미합니다. – Falmarri
내 탭이 서로 의존하지 않습니다. 사용자가 탭을 클릭하여 클래스 화면으로 이동하면 다운로드를 수행하기 만하면됩니다. 내 탭은 활동을 가리 킵니다. –