I want to add a title to a ListView, for example that has a heading title and then all the elements of the view.
Then I will leave the code of the app, to make it clearer:
MainActivity:
public class MainActivity extends AppCompatActivity {
private static DrawerLayout drawerLayout;
private static ListView menuLateral;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ejecuta();
}
public void ejecuta(){
drawerLayout=(DrawerLayout)findViewById(R.id.miDrawerLayout);
//mainLayout=(LinearLayout)findViewById(R.id.mainLayout);
menuLateral=(ListView)findViewById(R.id.menuLateral);
String opciones[]={"Opcion 1","Opcion 2","Opcion 3","Opcion 4","Opcion 5", "Opcion 6"};
ArrayAdapter<String> adp=new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1, opciones);
menuLateral.setAdapter(adp);
menuLateral.setFocusableInTouchMode(true);
menuLateral.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in;
if (position==0){
in=new Intent(getApplicationContext(), Main2Activity.class);
startActivity(in);
}
}
});
}
}
activity_main.xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/miDrawerLayout"
>
<!--Contenido principal-->
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
></LinearLayout>
<!--Menu Lateral-->
<ListView
android:layout_gravity="start"
android:id="@+id/menuLateral"
android:layout_width="200dp"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_bright"
></ListView>
</android.support.v4.widget.DrawerLayout>