当我在Android中放置ListItem按钮单击事件时,ListItem Click事件不起作用

时间:2014-05-24 12:59:42

标签: android button android-listview listitem custom-adapter

我做了一个活动,我有一个ListView,有自定义ListAdater,在ListView中有些ListItem会有按钮而有些没有,所以没有按钮的ListItems很容易点击,但ListItems有按钮不可点击,我试图找到任何解决方案,如果有任何伙伴知道帮助我,谢谢你提前..!我的代码块是: 的 ListItem.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:padding="10dp" >

    <TextView
        android:id="@+id/tv_trans_id_raw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:gravity="center"
        android:text="Trans ID"
        android:textSize="12dp" />

    <TextView
        android:id="@+id/tv_trans_desc_raw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Description"
        android:textSize="12dp" />

    <TextView
        android:id="@+id/tv_trans_date_raw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:text="Date"
        android:textSize="12dp" />

    <TextView
        android:id="@+id/tv_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/tv_trans_date_raw"
        android:layout_marginRight="10dp"
        android:text="status"
        android:textSize="12dp"
        android:visibility="gone" />

    <Button
        android:id="@+id/btn_issue"
        android:layout_width="80dp"
        android:layout_height="25dp"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/tv_status"
        android:background="@drawable/issu_refund_btn"
        android:visibility="gone" />

</RelativeLayout>

CustoAdapter.java

package com.epe.tp.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.ep.trustedPAYER.R;
import com.epe.tp.ui.DisputeSteponeActivity;
import com.epe.tp.ui.HomeActivity;
import com.epe.tp.util.Const;

public class SentPaymentAdapter extends BaseAdapter {
    public ArrayList<HashMap<String, String>> sentPaymentArray;
    private Context mContext;

    Intent i;

    public SentPaymentAdapter(Context paramContext, ArrayList<HashMap<String, String>> paymentList) {
        this.mContext = paramContext;
        this.sentPaymentArray = paymentList;

    }

    public int getCount() {
        return this.sentPaymentArray.size();
    }

    public Object getItem(int paramInt) {
        return Integer.valueOf(paramInt);
    }

    public long getItemId(int paramInt) {
        return paramInt;
    }

    public View getView(final int paramInt, View paramView, ViewGroup paramViewGroup) {
        LayoutInflater localLayoutInflater = (LayoutInflater) this.mContext.getSystemService("layout_inflater");
        Viewholder localViewholder = null;
        if (paramView == null) {
            paramView = localLayoutInflater.inflate(R.layout.raw_dashboard, paramViewGroup, false);
            localViewholder = new Viewholder();

            localViewholder.tv_date = ((TextView) paramView.findViewById(R.id.tv_trans_id_raw));
            localViewholder.tv_desc = ((TextView) paramView.findViewById(R.id.tv_trans_desc_raw));
            localViewholder.tv_amount = ((TextView) paramView.findViewById(R.id.tv_trans_date_raw));
            localViewholder.tv_status = ((TextView) paramView.findViewById(R.id.tv_status));
            localViewholder.btn_issue = ((Button) paramView.findViewById(R.id.btn_issue));
            localViewholder.tv_status.setVisibility(View.VISIBLE);

            paramView.setTag(localViewholder);

        } else {

            localViewholder = (Viewholder) paramView.getTag();
        }

        localViewholder.tv_date.setText(sentPaymentArray.get(paramInt).get(Const.TAG_DATE_ADDED));
        localViewholder.tv_desc.setText(sentPaymentArray.get(paramInt).get(Const.TAG_DESCRIPTION));
        localViewholder.tv_amount.setText(sentPaymentArray.get(paramInt).get(Const.TAG_ORDER_AMOUNT));
        localViewholder.tv_status.setText(sentPaymentArray.get(paramInt).get(Const.TAG_STATUS));
        if (localViewholder.tv_status.getText().toString().equalsIgnoreCase("Paid")) {
            localViewholder.btn_issue.setVisibility(View.VISIBLE);
            localViewholder.btn_issue.setBackgroundResource(R.drawable.issu_refund_btn);
        } else if (localViewholder.tv_status.getText().toString().equalsIgnoreCase("Processing")) {
            localViewholder.btn_issue.setVisibility(View.VISIBLE);
            localViewholder.btn_issue.setBackgroundResource(R.drawable.issue_refund_btn);
        } else {
            localViewholder.btn_issue.setVisibility(View.GONE);
        }
        localViewholder.btn_issue.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent i = new Intent(mContext, DisputeSteponeActivity.class);
                mContext.startActivity(i);

            }
        });
        return paramView;

    }

    static class Viewholder {

        TextView tv_date;
        TextView tv_desc;
        TextView tv_amount;
        TextView tv_status;
        Button btn_issue;

    }

}

1 个答案:

答案 0 :(得分:0)

android:focusable="false"添加到所有文字视图和按钮。