itemclicklistener上的Android Listview无法正常工作

时间:2011-09-06 10:30:27

标签: android

在我的应用程序中,我在Listview中绑定了四个Text视图,我在getview方法中使用了setOnItemClickListener,但是它没有正常工作,有些行点击而有些没有点击。

这个我的代码nd tm1是listview

public View getView(int position, View convertView,
        ViewGroup parent) {
    String mEntry = mList.get(position);

    LayoutInflater vi = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    convertView = vi.inflate(R.layout.custom_tid, null);

    TextView mDate = (TextView) convertView.findViewById(R.id.txtdate);
    TextView mtime = (TextView) convertView
            .findViewById(R.id.textView1);
    TextView mDet = (TextView) convertView.findViewById(R.id.textView2);
    final TextView mLoc = (TextView) convertView.findViewById(R.id.textView3);
    final CheckBox ch = (CheckBox) convertView
            .findViewById(R.id.btnadd);
    mDate.setTextSize(17);

    boolean isDate = false;
    for (int i = 0; i < dateform.size(); i++) {
        if (dateform.get(i).equals(mEntry)) {
            isDate = true;
            break;
        }
    }

    if (position % 2 == 0) {
        convertView.setBackgroundColor(Color.parseColor("#FAFEBF"));
    } else {
        convertView.setBackgroundColor(Color.parseColor("#D0E7CE"));
    }
    if (isDate) {
        mDate.setText(mEntry);
        mDate.setVisibility(View.VISIBLE);
        mDate.setGravity(Gravity.CENTER);
        mDate.setBackgroundColor(Color.parseColor("#89C5C1"));
        mDate.setHeight(30);
        mtime.setVisibility(View.GONE);
        mDet.setVisibility(View.GONE);
        mLoc.setVisibility(View.GONE);
        ch.setVisibility(View.GONE);
    } else {
        mDate.setVisibility(View.GONE);
        ch.setVisibility(View.VISIBLE);
        mtime.setVisibility(View.VISIBLE);
        mDet.setVisibility(View.VISIBLE);
        mLoc.setVisibility(View.VISIBLE);
        String[] tv = mEntry.split("#");
        String time = tv[0].toString();
        mtime.setText(time);
        String det = tv[1].toString();
        mDet.setText(det);
        String Loc = tv[2].toString();
        mLoc.setText(Loc);
        mLoc.setTag(c++);
        ch.setTag(count++);

        tm1.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(arg0.getContext(), ""+arg2, Toast.LENGTH_SHORT).show();

            }
        });

0 个答案:

没有答案