Implement screens in list fragment

1

I'm working on my first project with ListFragment looking on the internet for tutorials and even the online course I'm doing.

When the onListItemClick is created, it sends Toast to the screen, but I want it to open a new screen instead of displaying a message when it clicks the list item. For the record, in this project I'm using ActionBarSherlock . Here's the code I've written 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
  }

Thank you for the help of the community. Thank you.

    
asked by anonymous 26.02.2015 / 22:20

1 answer

3

If you want to start a new Activity , just a simple Intent :

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

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

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

Where OutroFragment is the Fragment you want to open, and R.id.contentor is the container in the layout where ListFragment is and where OutroFragment is.

Hope it helps. Say something if you need more help.

    
26.02.2015 / 22:52