小编Spu*_*uDy的帖子

无法在活动中找到onClick(View)方法

膨胀布局中的按钮单击在运行时失败,因为找不到该方法.E/AndroidRuntime(921):java.lang.IllegalStateException:在活动中找不到onClick(View)方法但是,如果从主布局点击按钮,则工作正常.我做错了什么?

更新:更改代码... stil失败...添加错误日志我想让我的所有按钮都在ome方法中处理.

主要活动课

package com.android.insertview;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Toast;

public class InsertViewActivity extends Activity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /*LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup parent = (ViewGroup)findViewById(R.id.main_view);
        inflater.inflate(R.layout.volume_control, parent);*/

        LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
        View v = vi.inflate(R.layout.volume_control, null);    
        View insertPoint = findViewById(R.id.main_view);
        ((ViewGroup) insertPoint).addView(v, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT
                                                                            , ViewGroup.LayoutParams.WRAP_CONTENT));
    } …
Run Code Online (Sandbox Code Playgroud)

android onclick

21
推荐指数
1
解决办法
6万
查看次数

标签 统计

android ×1

onclick ×1