How can I change that instead of showing a menu, just show me another layout

0

I charge the menu the onCreateMenu that contains in a ListView are some telephone contacts , that when you press them (Item) they take me to a activity called Details.

public class MainActivity extends Activity implements View.OnClickListener {
    ImageButton floatButton;
    private AmigoAdapter adapter;

    public static ArrayList<Amigo> listaAmigos = new ArrayList<Amigo>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView lvAmigos = (ListView) findViewById(R.id.lvAmigos);
        adapter = new AmigoAdapter(this,MainActivity.listaAmigos);
        lvAmigos.setAdapter(adapter);

        registerForContextMenu(lvAmigos);

        floatButton = (ImageButton) findViewById(R.id.btRegistro);
        floatButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),
                        "Button is clicked", Toast.LENGTH_LONG).show();
            }
        });

        ImageButton btRegistro = (ImageButton) findViewById(R.id.btRegistro);
        btRegistro.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        adapter.notifyDataSetChanged();
    }

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_listado, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.action_registrar:
                Intent intent = new Intent(this, Registro.class);
                startActivity(intent);
                break;
            default:
                break;
        }


        return super.onOptionsItemSelected(item);
    }



    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);

        getMenuInflater().inflate(R.menu.menu_context_listado, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {

        AdapterView.AdapterContextMenuInfo info =
                (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        final int itemSeleccionado = info.position;
        Amigo amigo = null;

        switch (item.getItemId()) {
            case R.id.action_fijo:
                amigo = MainActivity.listaAmigos.get(itemSeleccionado);
                String telefonoFijo = amigo.getTelefonoFijo();
                Intent intentLlamada = new Intent(Intent.ACTION_CALL);
                intentLlamada.setData(Uri.parse("tel: " + telefonoFijo));
                startActivity(intentLlamada);
                break;
            case R.id.action_movil:
                amigo = MainActivity.listaAmigos.get(itemSeleccionado);
                String telefonoMovil = amigo.getTelefonoMovil();
                Intent intentMovil = new Intent(Intent.ACTION_CALL);
                intentMovil.setData(Uri.parse("tel: " + telefonoMovil));
                startActivity(intentMovil);
                break;
            case R.id.action_editar:
                Intent intent = new Intent(this, Registro.class);
                intent.putExtra("posicion", itemSeleccionado);
                startActivity(intent);
                break;
            case R.id.action_eliminar:
                AlertDialog.Builder builder =
                        new AlertDialog.Builder(this);
                builder.setMessage(R.string.lb_esta_seguro)
                        .setPositiveButton(R.string.lb_si,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        MainActivity.listaAmigos.remove(itemSeleccionado);
                                        adapter.notifyDataSetChanged();
                                        Toast.makeText(MainActivity.this, R.string.lb_eliminado, Toast.LENGTH_LONG).show();
                                    }
                                })
                        .setNegativeButton(R.string.lb_no,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                    }
                                });
                builder.create().show();
                break;
            case R.id.action_email:
                amigo = MainActivity.listaAmigos.get(itemSeleccionado);
                Intent emailIntent = new Intent(Intent.ACTION_SEND);
                emailIntent.putExtra(Intent.EXTRA_EMAIL, amigo.getEmail());
                emailIntent.setType("message/rfc822");
                startActivity(Intent.createChooser(emailIntent, getString(R.string.selecciona_email)));
                break;
            case R.id.action_detalles:
                Intent intentDetalles = new Intent(this, Detalles.class);
                intentDetalles.putExtra("posicion", itemSeleccionado);
                startActivity(intentDetalles);

                Notification.Builder nBuilder = new Notification.Builder(this)
                        .setSmallIcon(android.R.drawable.ic_notification_overlay)
                        .setContentTitle("Prueba")
                        .setContentText("Esto es una notificacion");
                NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.notify(0, nBuilder.build());
                break;
            default:
                break;
        }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
*/
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btRegistro:
                // El usuario ha pulsado el botón de Registro. Se lanza la Activity para registrar un nuevo Amigo
                startActivity(new Intent(this, Registro.class));
                break;
            default:
                break;
        }
    }
}

    introducir el código aquí
    
asked by alvin 09.11.2017 в 03:26
source

2 answers

1

You must create a new activity, and within its XML recipes add a Lisview , load your contacts in the adapter and with the function:

miLista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if(position ==0){
                Intent intent = new Intent(actividad1.this,actividad2.class);
                startActivity(intent);
            }
            else if (position==1){
                Intent intent = new Intent(actividad4.this,actividad5.class);
                startActivity(intent);
            }
            else if(position==2){
                Intent intent = new Intent(actividad6.this,actividad7.class);
                startActivity(intent);
            }
 }
 });

It will help you every time you press a item to another activity in this case. You must add one more to each position do not forget that detail.

    
answered by 09.11.2017 / 05:33
source
0

The only way to do that is to edit your menu

/res/menu

Since you do not show the xml part of your menu, I guess it's something like that.

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_settings"
        android:showAsAction="never"
        android:title="@string/menu_settings"/>

</menu>

So what is to be modified? It is the attribute

showAsAction=”never”

so that it always appears in the overflow menu.

I'll give you an example of a menu I have.

<menu 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"
    tools:context=".Detalles.ActivityEmpleadoDetalles">
    <item
        android:id="@+id/action_edit"
        android:orderInCategory="1"
        android:title="Opc1"
        android:icon="@drawable/ic_pencil"
        android:iconTint="@color/bg_login"
        app:showAsAction="ifRoom" />

    <item
        android:id="@+id/action_ed"
        android:orderInCategory="1"
        android:title="Opc2"
        android:icon="@drawable/common_full_open_on_phone"
        android:iconTint="@color/bg_login"
        app:showAsAction="ifRoom" />

    <item
        android:id="@+id/action_delete"
        android:orderInCategory="2"
        android:icon="@drawable/ic_delete"
        android:iconTint="@color/bg_login"
        android:title="Opc3"
        app:showAsAction="ifRoom" />
</menu>

And then what was done to modify the way of viewing that menu, I leave you a description of the different attributes that you can add to the menu.

  

android: id . The identification ID of the element, with which we can   refer to that option.

     

android: title . The text that will be displayed for the option.

     

android: icon . The icon associated with the action.

     
    

android: showAsAction . If an action bar is being displayed, this attribute indicates whether the menu option will be displayed as an action button     or as part of the overflow menu. It can take several values:

         
      

ifRoom It will be shown as an action button only if there is space available.

             

withText . The option text will be displayed next to the icon in case it is shown as an action button.        never. The option will always be displayed as part of the overflow menu.

             

always . The option will always be shown as an action button. This value can cause the elements to overlap if there is not enough space for them.

    
  

Resulting in the following:

    
answered by 09.11.2017 в 05:09