Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单击表单元格上的侦听器不调用on-Click方法?_Android_Onclick_Tablelayout - Fatal编程技术网

Android 单击表单元格上的侦听器不调用on-Click方法?

Android 单击表单元格上的侦听器不调用on-Click方法?,android,onclick,tablelayout,Android,Onclick,Tablelayout,我通过编程膨胀行创建了一个表,并尝试在这些行中的每个视图上设置click listener,但似乎不起作用 这是我的充气机,我如何调用我的点击方法 inflater = (LayoutInflater) getActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < time.length; i++) { TableRow ro

我通过编程膨胀行创建了一个表,并尝试在这些行中的每个视图上设置click listener,但似乎不起作用

这是我的充气机,我如何调用我的点击方法

  inflater = (LayoutInflater) getActivity().getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);

    for (int i = 0; i < time.length; i++) {

        TableRow row = (TableRow) inflater.inflate(R.layout.week_view_cust,
                t_layout, false);
        TextView tv = (TextView) row.findViewById(R.id.time_week_tv);
        LinearLayout ll = (LinearLayout) row.findViewById(R.id.time_ll1);
        ll = (LinearLayout) row.findViewById(R.id.time_ll2);
        ll = (LinearLayout) row.findViewById(R.id.time_ll3);
        ll = (LinearLayout) row.findViewById(R.id.time_ll4);
        ll = (LinearLayout) row.findViewById(R.id.time_ll5);
        ll = (LinearLayout) row.findViewById(R.id.time_ll6);
        ll = (LinearLayout) row.findViewById(R.id.time_ll7);
        (new CustomListener()).onClick(ll);
        tv.setText("" + time[i]);
        t_layout.addView(row);

    }

我做错了什么?

据我所知,您没有在ClickListener上设置


您需要调用
ll.setOnClickListener(this)
对于每个单元格

我想您应该为每个线性布局设置onClickListener,如下所示:

猜测CustomListener正在实现onClick()方法


顺便说一句,你所说的
(new CustomListener()).onClick(ll)是什么意思?CustomListner()是我的类tat实现OnClickListenerThank:)日志在Logcat中更新,但是文本视图没有被创建……你知道吗?为什么,nt我实现click listener的方式不起作用呢?您为每个元素创建CustomListener()的新实例,这是不必要的,而且会占用大量内存
    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.time_ll1:

        LinearLayout ll = (LinearLayout)v.findViewById(R.id.time_ll1);
        TextView tv = new TextView(v.getContext());
        tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        tv.setTextSize(12);
        tv.setTextColor(000000);
        Log.i("============", "success");
        tv.setText("hello");
        ll.addView(tv);
        break;

    case R.id.time_ll2:
        break;
    case R.id.time_ll3:
        break;
    case R.id.time_ll4:
        break;
    case R.id.time_ll5:
        break;
    case R.id.time_ll6:
        break;
    case R.id.time_ll7:
        break;
    }
LinearLayout ll = (LinearLayout) row.findViewById(R.id.time_ll1);
ll.setOnClickListener(new CustomListener());
ll = (LinearLayout) row.findViewById(R.id.time_ll2);
ll.setOnClickListener(new CustomListener());
ll = (LinearLayout) row.findViewById(R.id.time_ll3);
ll.setOnClickListener(new CustomListener());
ll = (LinearLayout) row.findViewById(R.id.time_ll4);
ll.setOnClickListener(new CustomListener());
ll = (LinearLayout) row.findViewById(R.id.time_ll5);
ll.setOnClickListener(new CustomListener());
ll = (LinearLayout) row.findViewById(R.id.time_ll6);
ll.setOnClickListener(new CustomListener());
ll = (LinearLayout) row.findViewById(R.id.time_ll7);
ll.setOnClickListener(new CustomListener());