samedi 7 mars 2015

Learning Android Lists and nothing happens



Ok so I'm doing a very basic newbie app from Android bootcamp (Chapter 5, first activity)


The objective is to make a list, then when you click on the first item "Family Photography" it's suppose to show another page showing a picture of a family. Click on the second "Portrait Photography" it shows a picture of a lady. Click on the third "Picture People full site" it opens a new browser window that goes to the website.


So I believe I have built the strings and classes correctly to do this, but when I click on each link in my simulator I get nothing. No bug, no error, no crash...just acknowledgement from the screen that I did click on it.


Main Activity



package net.androidbootcamp.photographystudio;


import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class MainActivity extends ListActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] phototype={"Family Photography", "Portrait Photography", "Picture People Full Site"};
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, phototype));
}

protected void onLIstItemClick(ListView l, View v, int position, long id) {
switch(position){
case 0:
startActivity(new Intent(MainActivity.this, Portrait.class));
break;
case 1:
startActivity(new Intent(MainActivity.this, Family.class));
break;
case 2:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://ift.tt/N9RFYW")));
break;
}
}


@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}


Family.java



package net.androidbootcamp.photographystudio;

import android.app.Activity;
import android.os.Bundle;

public class Family extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.family);
}
}


Portrait.java package net.androidbootcamp.photographystudio;



import android.app.Activity;
import android.os.Bundle;

public class Portrait extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.family);
}
}


Layout activity_main.xml



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.androidbootcamp.photographystudio.MainActivity" >



</RelativeLayout>


family.xml



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/family"
android:src="@drawable/family" />

</RelativeLayout>


portrait.xml



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:contentDescription="@string/portrait"
android:src="@drawable/portrait" />

</RelativeLayout>


AndroidManifest.xml



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="net.androidbootcamp.photographystudio"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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=".Portrait"></activity>
<activity android:name=".Family"></activity>
</application>

</manifest>



Aucun commentaire:

Enregistrer un commentaire