onListItemClick未在ListActivity上调用

时间:2013-09-12 15:18:13

标签: android android-listview android-listfragment

我的活动扩展了ListActivvity,我在其中添加了onListItemClick()但是没有调用listitem click。

当我给我的视图充气并在getView()方法中返回该视图时,listitem click没有被调用,但是当我没有膨胀视图并直接调用super方法时它工作正常。

CustomArrayAdapter.java

package com.mobileinsight.presenter.form;

import android.content.Context;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mobileinsight.R;
import com.mobileinsight.common.SimpleMap;
import com.mobileinsight.common.Util;

public class CustomArrayAdapter extends ArrayAdapter<SimpleMap> {

    private Product[] objects;
    private Context _this;

    public CustomArrayAdapter(Context context, int resource, Product[] objects) {
        super(context, resource, objects);
        this.objects = objects;
        this._this = context;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) _this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

             rowView = inflater.inflate(R.layout.list_row, parent, false);
        } else {
            rowView = convertView;
        }

        TextView textView = (TextView) rowView.findViewById(R.id.text1);
        TextView detailview = (TextView) rowView.findViewById(R.id.text2);

              textView.setText("Text 1"));
//      textView.setClickable(true);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        detailview.setText(objects[position].getDetails());

        return rowView; //  not working
           // return super.getview(); // Working

    }

}

list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

     <TextView
         android:id="@+id/text1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_alignParentLeft="true"
         android:layout_gravity="center_vertical|left"
         android:layout_margin="6dip"
         android:layout_weight="2"
         android:ellipsize="end"
         android:gravity="center_vertical|left"
         android:singleLine="false"
         android:textAppearance="?android:attr/textAppearanceLarge"
         />

    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_gravity="center_vertical|right"
        android:layout_margin="6dip"
        android:layout_weight="0"
        android:ellipsize="none"
        android:gravity="center_vertical|right"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

试试这段代码,它可能会有所帮助..

public class CustomArrayAdapter extends ArrayAdapter<SimpleMap>
{
    LayoutInflater inflater;
    public CustomArrayAdapter(Context context) 
    {
        inflater = LayoutInflater.from(context);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;

        if (convertView == null) {
            rowView = inflater.inflate(R.layout.list_row, parent, false);
        } else {
            rowView = convertView;
        }

        TextView textView = (TextView) rowView.findViewById(R.id.text1);
        TextView detailview = (TextView) rowView.findViewById(R.id.text2);

        return rowView; 
    }
}