0

i want to create a class in my MainActivity:

MyCard customCard1 = new MyCard(cardTitle.getText().toString(),
                cardbuttonon.getText().toString(),
        cardbuttonon.getText().toString(),
        cardbuttonon.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String[] url={"url"};
                new onoff(MainActivity.this).execute(url);
            }});
        mCardView.addCard(customCard1);
        mCardView.refresh();

but he say me that the constructor MyCard(String,String,String,Object undefined is.

How can i define him on my MyCard:

package de.heron.cloudbox;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.fima.cardsui.objects.Card;

public class MyCard extends Card {

    public MyCard(String title, String desc, String string, Object setOnClickListener){
        super(title, desc); 
    }
    @Override
    public View getCardContent(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.card_ex, null);

        ((TextView) view.findViewById(R.id.title)).setText(title);
        ((TextView) view.findViewById(R.id.description)).setText(desc);

        return view;
    }
}

can someone help me by my problem?

why can i make it with 2 onclicklisteners:

MyCardXml customCard1 = new MyCardXml(cardTitle.getText().toString(),cardbuttonon = (Button) findViewById(R.id.cardbuttonon),cardbuttonoff = (Button) findViewById(R.id.cardbuttonoff),
                cardbuttonon.getText().toString(),cardbuttonoff.getText().toString(),
        cardbuttonon.getText().toString(),cardbuttonoff.getText().toString(),
        cardbuttonon.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                String[] url={"http://everhome.de/api/applive/", "8ef43502ad3dc04f87b4a48b993878c0","/" + KEY_ID,"/" + KEY_COST};
                new onoff(MainActivity.this).execute(url);
                }}

                ),cardbuttonoff.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String[] url={"http://everhome.de/api/applive/", "8ef43502ad3dc04f87b4a48b993878c0","/" + KEY_ID,"/" + KEY_COST};
                    new onoff(MainActivity.this).execute(url);
                }}

                ));
        mCardView.addCard(customCard1);
        mCardView.refresh();
3
  • I'm not sure what you're doing, but MyCard's constructor isn't even using half its arguments, your variable names are bizarre, and your indentation is screwed up. Why is MyCard's constructor taking a parameter called setOnClickListener? That name doesn't sound like it describes an object; that sounds like it describes an action. Commented Jul 5, 2013 at 9:14
  • 1
    Can you please share exact exception. Beacuse MyCard customCard1 = new MyCard(..) is not completely closed. Commented Jul 5, 2013 at 9:15
  • To elaborate on Ashish's comment: you're missing a closing parenthesis on the MyCard constructor call. Commented Jul 5, 2013 at 9:16

3 Answers 3

1

Your constructor needs an Object as the fourth parameter. You are not passing an object in the fourth parameter when you are constructing the object.This will solve the error

MyCard customCard1 = new MyCard(cardTitle.getText().toString(),
            cardbuttonon.getText().toString(),
    cardbuttonon.getText().toString(),
    new View.OnClickListener() {
        public void onClick(View v) {
            String[] url={"url"};
            new onoff(MainActivity.this).execute(url);
        }});
Sign up to request clarification or add additional context in comments.

1 Comment

but whats when i have another button with a onclicklistener
1

you should pass View.OnClickListener to your MyCard constructor instead of Object

Change

   public MyCard(String title, String desc, String string, Object setOnClickListener){
        super(title, desc); 
    }

with

   public MyCard(String title, String desc, String string,  View.OnClickListener setOnClickListener){

Comments

0

You have to change your constructor like this

public MyCard(String title, String desc, String string, OnClickListener clickListener){

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.