Implement screens in list

Asked

Viewed 183 times

1

I’m working on my first project with ListFragment searching the internet in tutorials and even in the online course I’m doing.

When the onListItemClick he sends a Toast to screen, but I want you to open a new screen instead of showing a message when you click on the list. For the record, in this project I’m using Actionbarsherlock. This is the code I’ve made for now:

ListView ListViewSegunda;
String[] linhas = {"305", "306", "315"};    
@Override
public void onActivityCreated(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);        
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, linhas);
    setListAdapter(adapter);
}       
@Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    // do something with the data
  }

I appreciate the help from the community. Thank you.

1 answer

3

If you stop starting a new one Activity, just one simple Intent:

Intent i = new Intent(Intent.ACTION_VIEW, uriAplicacao); // Ou algo do género
getActivity().startActivity(i);

If it’s to replace the ListFragment by another Fragment is already more complicated. I usually send the request to the Activity and there do the following:

getFragmentManager().beginTransaction().replace(R.id.contentor, new OutroFragment()).commit();

In which OutroFragment is the Fragment that wants to open, and R.id.contentor is the container in the layout where the ListFragment and where the OutroFragment.

I hope it helps. Say something if you need more help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.