Help with List View

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Help with List View

Postby android_beggnr » Thu Nov 06, 2008 8:51 pm

I am a novice in Java programming and to Android. Can some body point me to a correct answer.

This program is my 2nd program, I already wrote the Hello Andriod program and successfully executed it.

package com.mallik.andriod.hello;

import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;


public class HelloAndriod extends ListActivity {
private ListAdapter mAdapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor c = getContentResolver().query(People.CONTENT_URI,null,null,null,null);
startManagingCursor(c);
String[] columns = new String[] {People.NAME};
int[] names = new int[] {R.id.row_entry};

mAdapter = new SimpleCursorAdapter(this,R.layout.main,c,columns,names);
setListAdapter(mAdapter);

setContentView(R.layout.main);
}

/* (non-Javadoc)
* @see android.app.ListActivity#onListItemClick(android.widget.ListView, android.view.View, int, long)
*/
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Intent I = new Intent(Intent.ACTION_CALL);
Cursor c = (Cursor)mAdapter.getItem(position);
long phoneId = c.getLong(c.getColumnIndex(People.PRIMARY_PHONE_ID));
I.setData(ContentUris.withAppendedId(Phones.CONTENT_URI, phoneId)); ;
startActivity(I);
}
}

AndriodManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mallik.andriod.hello">

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndriod"
android:label="Hello Mallik">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
</application>
</manifest>

Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
/>
<TextView android:id="@+id/row_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>


The Program on the emulator is always crashing with error, this program has stopped unexpectedly. Please try again.

Can some bosy point me my mistake. I am soory for being so dumb.
android_beggnr
Freshman
Freshman
 
Posts: 5
Joined: Thu Nov 06, 2008 8:45 pm

Top

Postby MrSnowflake » Thu Nov 06, 2008 9:53 pm

Check you Log!!!!!!!!

And this isn't a tutorial!

And as a solution to your problem: When you are using a ListActivity you should have a ListView in you layout with the id: android:id="@android:list". Check your docs!
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests