单击ListView

时间:2017-05-03 15:33:45

标签: android listview android-adapter

我想点击列表视图并更新所选记录。但是,当我点击列表时,我的应用程序停止工作..

这是我的适配器代码,

 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(ViewAllBills.this, ViewBills.class);
        HashMap<String,String> map =(HashMap)parent.getItemAtPosition(position);
        String billId = map.get(Config.TAG_ID).toString();
        intent.putExtra(Config.BILL_ID,billId);
        startActivity(intent);
    }

这段代码有什么问题吗?

实际上我仍然是Android编程的新手,并没有真正承担它。在我点击列表视图并且应用程序停止工作后,这是我的LogCat ......这意味着什么?

com.example.Dino.dino E / AndroidRuntime:FATAL EXCEPTION:main

处理:com.example.Dino.dino,PID:3280                                                                                    java.lang.IllegalStateException:在父类或祖先上找不到方法click(View)for android:在视图类android.widget.LinearLayout上定义的onClick属性                                                                                        在android.view.View $ DeclaredOnClickListener.resolveMethod(View.java:4532)                                                                                        在android.view.View $ DeclaredOnClickListener.onClick(View.java:4496)                                                                                        在android.view.View.performClick(View.java:5265)                                                                                        在android.view.View $ PerformClick.run(View.java:21534)                                                                                        在android.os.Handler.handleCallback(Handler.java:815)                                                                                        在android.os.Handler.dispatchMessage(Handler.java:104)                                                                                        在android.os.Looper.loop(Looper.java:207)                                                                                        在android.app.ActivityThread.main(ActivityThread.java:5728)                                                                                        at java.lang.reflect.Method.invoke(Native Method)                                                                                        在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)                                                                                        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

3 个答案:

答案 0 :(得分:1)

在您的布局文件中读取错误消息你有一个声明android:onclick =“click”但是你的Activity / Fragment中没有单击(View)。您需要提供此方法。

答案 1 :(得分:1)

android:onclick="click" remove this line in your xml.

答案 2 :(得分:0)

尝试

1。在ViewBills中实现View.OnClickListener,例如

ViewBills implements View.OnClickListener

2. 覆盖onClick方法

@Override 
public void onClick(View v) {
 //handle click
}