Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old January 7th, 2013, 05:23 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jan 2013
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Question Begginer

Hi, good night freaks.

Speaking from Brazil and I'm starting to produce some app for Android(or trying to do that).

I bought a book that learn something about it and right now I'm trying to get contacts that are in my contact list and return it to a list in my app.

The code that you are going to see is a copy from what is in my book.

[HIGH]package teste.v1;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class ExemploListaContatos extends Activity {
private ListAdapter adaptador;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Uri uri = ContactsContract.Contacts.CONTENT_URI;

Cursor c = getContentResolver().query(uri,null,null,null,null );
startManagingCursor(c);

String[] colunas = new String[] { ContactsContract.Contacts.DISPLAY_NAME };
int[] campos = new int[]{R.id.nome};

adaptador = new SimpleCursorAdapter(this,R.layout.layout_contatos, c,colunas,campos);

setListAdapter(adaptador);
}

protected void onListItemClick(ListView l, View v, int position, long id){
super.onListItemClick(l,v,position,id);

Cursor c = (Cursor) adaptador.getItem(position);

String nomeColuna = ContactsContract.Contacts.DISPLAY_NAME;
String nome = c.getString(c.getColumnIndexOrThrow(nomeColuna));
Toast.makeText(this, "Contato Selecionado" + nome, Toast.LENGTH_LONG).show();
}
}
[/HIGH]

The point is, the "
setListAdapter(adaptador);" and "
super
.onListItemClick(l,v,position,id);" are with the red line in Eclipse. I'm trying to fix that but I can't find anything.Eclipse is saying method undefined for the type Activity.

Please, help! I don't know what more can I do.

THanks.

cmdmss is offline  
Last edited by cmdmss; January 7th, 2013 at 05:23 PM. Reason: english error
Reply With Quote
sponsored links
Reply


Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:18 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.