tags:

views:

152

answers:

1

Hi ive got a custom listview and im trying to start a new activity on a button click however an occur occurs when i try to set an intent , i guess this is because my custom array class does not extend activity. The buttons trigger an alarm to be set. Is there any way i can get an intent to work in this class?

Below is my code for the class.

public class customArray extends ArrayAdapter<String> {
SatMain sm = new SatMain();


int resource;

public customArray(Context cont, int _resource, List<String> items) {
    super(cont, _resource, items);
    resource = _resource;

}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    RelativeLayout rl;

    String prod = getItem(position);
    if (convertView == null) {
        rl = new RelativeLayout(getContext());
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        vi.inflate(resource, rl, true);
    } else {
        rl = (RelativeLayout) convertView;
    }
    TextView t1 = (TextView) rl.findViewById(R.id.text12);
    t1.setText(prod);
    final Button b1 = (Button) rl.findViewById(R.id.widget29);

    b1.setText("efwrf");

    if (position == 2) {

        b1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {


                 Intent intent = new Intent(customArray.class, SatMain.class);
                    startActivity(intent);


                b1.setText("alarm set");



            }
        });

    }

    if (position == 0) {

        b1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

            }
        });
        b1.setText("number 0");
    }

    return rl;
}

}

+1  A: 

It just sais that the constructor for intent is undefined ( havent run it as its a compile error)

Well, you need to use a proper Intent constructor. Instead of using customArray.class (which is a Class) or customArray (which is an ArrayAdapter), you need to supply a Context. You are using getContext() several places in this code -- use it here as well, I suppose.

CommonsWare
Ah brilliant its working now thanks.
SamB09