I'm reading and working with a tutorial which is about how create sliding menu in android app ... the address of tutorial is this .. the activity-main.xml is this :
//activity-main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
actually, I want to add a button to fragment_find_people.xml
layout to show a simple toast ...
//fragment_find_people.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/btnDelete"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="enter" />
</RelativeLayout>
i have not work with fragment class and view so i am confused ... i found out i could not create Button object in "FindPeopleFragment" class which extend Fragment .... there is class which is :
public class FindPeopleFragment extends Fragment {
Button btnAdd;
public FindPeopleFragment(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
return rootView;
}
}
when I wrote :
btnAdd=(Button)this.....
it shows no suggestion to find element by id ... no thing showed ... :( when I create a button in onCreate of MainActivity the program crashed !!!:(
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
..
...
..
btnADD=(Button)this.findViewById(R.id.btnAdd);
btnADD.setOnClickListener(new clickListener());
}
.
class clickListener implements View.OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
.
}
where i must create my Button and call its OnClickListener ???
thanks for helping
You could add a layout which holds the listview inside of the sliding menu,and by this you could add views before / after the sliding menu. for example.
<LinearLayout
android:id="@+id/left_drawer"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#fff"
android:orientation="vertical" >
<TextView
android:id="@+id/user_fc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:gravity="left|center_vertical"
android:layout_marginLeft="3dp"
android:textStyle="italic" />
<ListView
android:id="@+id/slider_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:choiceMode="singleChoice"
android:divider="@android:color/black"
android:dividerHeight="1dp" />
</LinearLayout>
the textView will appear just before the sliding menu listview.