views:

36

answers:

0

Well, hello everyone. I'm just a beginner in Android so excuse me if my question is dumb, but still I can't find an answer to what's happened.

I'm writing an application that consists of 3 activities and 1 service. The service keeps track of my content's lists, like that:

private void setLists() {
 this.lists = new HashMap<String, TaskList>();
    this.getLists().put("current", new TaskList(getString(R.string.current)));
 this.getLists().put("upcoming", new TaskList(getString(R.string.upcoming)));
}

public TaskList getList(String key) {
return this.getLists().get(key);
}

And when in activity#1 I choose one of the lists, it is displayed in activity#2 like that:

public void onServiceConnected(ComponentName name, IBinder service) {
this.appService=((LadyOrgService.LocalBinder)service).getService();
String key = this.params.getString("listID");
this.list = this.appService.getList(key);
 this.displayNotificationMessage(Integer.toString(this.list.getItemCount()));
this.displayTaskList(this.list);
}

public void displayTaskList(TaskList list) {
 this.setTaskListWidgets();
 list.getView().setVisibility(1);
}

private void setTaskListWidgets() {
this.appService.getList("current").setView(this, (ListView)findViewById(R.id.currentTaskList));
this.appService.getList("upcoming").setView(this, (ListView)findViewById(R.id.upcomingTaskList));
for(TaskList taskList : this.appService.getLists().values()) {  
    taskList.getView().setVisibility(0);
}
 this.newTaskButton = (Button)findViewById(R.id.buttonNewTask);
 this.pauseAllButton = (Button)findViewById(R.id.buttonPauseAll);
 this.deleteAllButton = (Button)findViewById(R.id.buttonDeleteAll);
}

And the TaskList class is composed of a ListView and some other stuff which is done like that:

public void setView(Activity app, ListView view) {
this.list = view;
if (this.adapter==null) {
this.adapter = new ArrayAdapter<Task>(app, android.R.layout.simple_list_item_1);
}
this.list.setAdapter(this.adapter);
this.list.setOnItemClickListener(this);
}

So basically I'm just assigning my lists to different widgets and make all of them invisible except for the one I need (maybe it's not a best design solution but still it's IMHO a better tradeoff than having a separate array of items and assigning a new adapter to the same widget each time I need to display another list). reworked

The problem is: the first time I start activity#2 it works fine, listens to all clicks on items and so on. But then, if I pause the activity or return from it to the first one (to select another list or to reopen this one), something strange happens. Only the list selected first is shown, and it only listens to clicks on items I add AFTER the activity was opened back. And if I click on an item added before I push the 'back' button on my device, it does nothing. Could anyone please tell me what I am doing wrong?

UPD. I even reworked my app to the version with 1 ListView and ArrayLists in the TaskList class. It solved the problem of switching lists (so that I don't have to hide anything, I just render an array to a widget). But the problem with old items not listening to clicks still exists. Is there any cure?