Reloading data in onOptionsItemSelected during a chunk of (same) transaction
I have a problem with my android app. I have an activity with a fragment that contains a list of items (about a forum with an id) and an action bar with 2 buttons: refresh and refresh. I want to send the current id to a "new button" that open the intent of another activity.
The problem is that when in a fragment (ListTopic.java) I run another (same) fragment (ListTopic.java) to open a different forum (then with a different id), the "new button" has the same ID of the previous forum, and not new.
So if I open a forum with ID 33, when I click the sub-forum with ID 200, the new button has an ID ID.
This is the code where I take the new forumId:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_list_topics, container, false);
parent = new Forum();
count = 10;
imageLoader = new ImageLoader(getActivity());
Bundle bundle = getArguments();
pkg = getActivity().getPackageName();
forumId = bundle.getString(pkg + "FORUMID");
user = bundle.getString(pkg + "USER");
password = bundle.getString(pkg + "PASS");
nome = bundle.getString(pkg + "NOME");
parent = (Forum) bundle.getSerializable(pkg + "parent");
This is the end of the code:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.menu_topic, menu);
super.onCreateOptionsMenu(menu,inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_topic_update:
this.dialog = new ProgressDialog(getActivity());
subForumList = new ArrayList<Forum>();
TopicList asyncTopic = new TopicList();
asyncTopic.execute();
break;
case R.id.menu_topic_new:
Intent newTopic = new Intent(getActivity(), NewTopicActivity.class);
newTopic.putExtra(pkg + "USER", user);
newTopic.putExtra(pkg + "PASS", password);
newTopic.putExtra(pkg + "FORUMID", forumId);
startActivity(newTopic);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Thank you so much!
source to share
No one has answered this question yet
Check out similar questions: