I have this ListView that takes the Items of a String-arraay that I have defined in my strings.xml, how can I make these items appear in the center of the screen, with the text centered?
<ListView
android:id="@+id/listaprincipal"
android:layout_width="match_parent"
android:layout_height="261dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical|center_horizontal"
android:alwaysDrawnWithCache="false"
android:animateLayoutChanges="false"
android:entries="@array/mainlist"
android:textAlignment="center" />
This is the class that calls the list and where I have defined the action of each item:
listaprincipal=(ListView)findViewById(R.id.listaprincipal);
listaprincipal.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
Intent intent = new Intent(MainActivity.this,fragmain.class);
intent.putExtra("posicion","0");
startActivity(intent);
break;
case 1:
Intent intent1 = new Intent(MainActivity.this,fragmain.class);
intent1.putExtra("posicion","1");
startActivity(intent1);
break;
case 2:
Intent intent2 = new Intent(MainActivity.this,fragmain.class);
intent2.putExtra("posicion","2");
startActivity(intent2);
break;
}
}
});