0

Hi guys I'm new in android so please help me, I want to build an application android which have 2 fragment tabs :

  1. Home
  2. Search

The second fragment should contain 2 more fragments, 1 for searching & 1 for result.

I create a fragment (Search) which contain a simple search view (which I define only in the xml layout)

This is my code :

Main Activity :

public class MDASA extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mdasa);
        // add tabs here
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
          // ...
    }
}

Fragment (searching) :

public class FreeOpinion extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment, container, false);
        return v;
    }

}

Fragment.xml :

<SearchView
    android:id="@+id/simpleSearchView"
    style="@style/testSearch"
    android:queryHint="Search here"/>

I get the search view but it doesn't do any thing. How can I create a second fragment that contain the result of the searching ?

This is the result of my code: a screenshot of my app-1

PS :

I found a question that is similar to mine, but as a result I get a second search view in the ActionBar
a screenshot of my app-2

There is also this code which seems very useful but I don't know where should i put it (because i have to put the search view in the fragment)

Thanx a lot :)

Community
  • 1
  • 1
Asma
  • 137
  • 3
  • 15
  • What do you mean "it doesn't do any thing"? Why do you do to test this? What happens? – Code-Apprentice May 08 '17 at 00:16
  • Code-Apprentice Yes, I test it , I can write on it but for now I can't search with it because i define the search view only in the xml layout. This is the first time I work with fragments so I don't now what should i do , beside I searched a lot & I didn't found any code or tutorial useful – Asma May 08 '17 at 09:01
  • @Code-Apprentice ,I found this [answer](http://stackoverflow.com/questions/7230893/android-search-with-fragments/10479208#10479208) but i don't know how to use it because in the main activity i have 2 fragments – Asma May 08 '17 at 11:03

0 Answers0