Buen día a todos. Voy a responder unas preguntas que me hicieron
Pablo.java
activity_my.xml
pablo.xml
AndroidManifest.xml
Descarga el proyecto
video
Primero le recomiendo que vean estos tutos
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MyActivity extends ActionBarActivity {
ListView lista;
String[] personas = {
"pablo",
"ramiro",
"vilma",
"canela",
"tito",
"nicolas",
"maira",
"pepita",
"honguito"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
lista = (ListView) findViewById(R.id.listView1);
ArrayAdapter adaptador = new ArrayAdapter(this, android.R.layout.simple_list_item_1, personas);
lista.setAdapter(adaptador);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterView, View view, int posicion, long l) {
//Toast.makeText(getApplicationContext(), "posicion " + (i + 1) + personas[i], Toast.LENGTH_SHORT).show();
switch (posicion) {
case 0 :
Intent ii = new Intent(getApplicationContext(), Pablo.class);
startActivity(ii);
break;
case 1 :
Toast.makeText(getApplicationContext(), "hola soy ramiro", Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getApplicationContext(), "no soy ramiro ni pablo", Toast.LENGTH_SHORT).show();
}
}
});
}
}
Pablo.java
public class Pablo extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pablo);
}
}
activity_my.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MyActivity"> <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listView1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" /> </RelativeLayout>
pablo.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="soy pablo"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="205dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tatoado.listviewintent" > <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MyActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Pablo"></activity> </application> </manifest>
Arriba deben agregar si o si el en el AndroidManifest.xml como les indique arriba.
<activity android:name=".Pablo"></activity>