2 qq 22200361 qq_22200361 于 2016.03.06 11:11 提问

Attempt to invoke virtual method

public class SecondView extends LinearLayout {
private TextView tv_hour,tv_minute,tv_second,tv_millisecond;
private ListView mListView;
private ArrayAdapter adapter;
private Button btn_start,btn_pause,btn_reset,btn_resume,btn_lap;

public SecondView(Context context) {
    super(context);
}

public SecondView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public SecondView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    init();
}

public void init(){
    btn_lap = (Button) findViewById(R.id.btn_lap);
    btn_pause = (Button) findViewById(R.id.btn_pause);
    btn_reset= (Button) findViewById(R.id.btn_reset);
    btn_resume = (Button) findViewById(R.id.btn_resume);
    btn_start = (Button) findViewById(R.id.btn_start);

    btn_start.setVisibility(VISIBLE);
    btn_resume.setVisibility(GONE);
    btn_reset.setVisibility(GONE);
    btn_pause.setVisibility(GONE);
    btn_lap.setVisibility(GONE);

    tv_hour = (TextView) findViewById(R.id.tvHour);
    tv_millisecond = (TextView) findViewById(R.id.tvMilisecond);
    tv_minute = (TextView) findViewById(R.id.tvMinute);
    tv_second = (TextView) findViewById(R.id.tvSecond);

    mListView = (ListView) findViewById(R.id.lvWatching);
    adapter = new ArrayAdapter(getContext(),android.R.layout.simple_list_item_1);
    mListView.setAdapter(adapter);
}

}

1个回答

qq_17250009
qq_17250009   2016.03.06 19:58

先使用LayoutInflater.inflate 然后再findViewByid

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!