我想在我的 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();
但他说我构造函数 MyCard(String,String,String,Object undefined 是。
我如何在我的 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;
}
}
有人可以帮我解决我的问题吗?
为什么我可以用 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();