How to make an item in the listview of eclipse open a "different activity"?

0

I am creating an android application in eclipse, which has the following listview, when pressing any of them I need you to send me to another activity

This is the code that I have in my activity, try to make it with that switch but it does not work for me, I do not know what I'm doing wrong

package com.example.misapplications1;

import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener { public ListView ltvApplications;

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



    ltvAplicaciones=(ListView)findViewById(R.id.ltvAplicaciones);

    ArrayAdapter<CharSequence> adaptador=ArrayAdapter.createFromResource(this,R.array.lista,android.R.layout.simple_list_item_1);

    ltvAplicaciones.setAdapter(adaptador);

    ltvAplicaciones.setOnItemClickListener(this);
}

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


public boolean onOptionsItemSelected(MenuItem opcion){
    switch (opcion.getItemId()){
    case R.id.salir:finish();break;
    case R.id.mnuAcerca: Intent acerca =new Intent(this,Acercade.class);
                       startActivity(acerca);finish();break;
    }
    return true;
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub
    switch(ltvAplicaciones.getSelectedItemPosition()) {
    case 0:
        Intent intencionLlama= new Intent(this,Llamar.class);
        startActivity(intencionLlama);
        finish();

    }

}

}

    
asked by Maria 08.04.2018 в 01:01
source

0 answers