android动态添加复选框编译错误

时间:2014-05-19 18:38:28

标签: android dynamic checkbox

我想知道我的错误,因为我的应用程序无法编译。 setonCheckedChangeListener(this);要求演员。 我正在尝试添加由","分隔的内容中的复选框。 (内容通过JSON下载)

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class SingleContactActivity  extends Activity {
int array_Count=0;
// The next part is in the onCreate method, after the data has been pulled out of my intent.
String[] seperatedString = list.split(", ");
Array_Count=seperatedString.length;

    LinearLayout my_layout = (LinearLayout)findViewById(R.id.list_label);

    for (int i = 0; i < Array_Count; i++) 
    {
        TableRow row =new TableRow(this);
        row.setId(i);
        row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        CheckBox checkBox = new CheckBox(this);
        checkBox.setOnCheckedChangeListener(this);
        checkBox.setId(i);
        checkBox.setText(seperatedString[i]);
        row.addView(checkBox);  
        my_layout.addView(row);
    }

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

SingleContactActivity应该实现OnCheckedChangeListener接口。

public class SingleContactActivity extends Activity implements OnCheckedChangeListener {