• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Begginer

cmdmss

Lurker
Jan 7, 2013
1
0
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.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones