Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

android programing problem with ListAdapter

Status
Not open for further replies.

ghattasak

Member level 1
Member level 1
Joined
Dec 31, 2012
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,595

Code Java - [expand]
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;
                }
        }



hello i am having trouble working with this i am a beginner in android and java i want to pull out contact name information and place them inside a string array MyName then use the inflater to map each contact name to a textfield in the xml file i also have a toggle button and an image that i would like to use separately for each row how can i do that? and how can i fix this code where the at the class MyAdapter is not accessible and is stating that it is undeclared and the setListAdapter creationg function is showing an error

Multiple markers at this line

The type Main.MyAdapter is not generic; it cannot be parameterized with arguments <String>
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top