1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
public class Main extends ListActivity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_view);
final String [] MyName = new String [10];
final int i=0;
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (people.moveToNext()){
int NameIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String Name = people.getString(NameIndex);
MyName[i] = Name.toString();
i++;
}
setListAdapter(new MyAdapter<String>(this,
android.R.layout.simple_list_item_1, R.id.textView1,
MyName));
}
class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource,
int textViewResourceId, String[] string) {
super(context, resource, textViewResourceId, string);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.contact_view, parent,false);
ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
TextView tv = (TextView) row.findViewById(R.id.textView1);
ToggleButton tb = (ToggleButton) row.findViewById(R.id.toggleButton1);
tv.setText(MyName[i]);
return row;
}
} |