【问题标题】:android dynamically add checkbox Compilation errorandroid动态添加checkbox编译报错
【发布时间】:2014-07-07 20:01:46
【问题描述】:

我想知道我做错了什么,因为我的应用程序无法编译。 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);
    }

非常感谢任何帮助。

【问题讨论】:

    标签: android dynamic checkbox


    【解决方案1】:

    SingleContactActivity 应该实现OnCheckedChangeListener 接口。

    public class SingleContactActivity extends Activity implements OnCheckedChangeListener {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 2012-12-13
      • 2018-05-27
      相关资源
      最近更新 更多