列表项单击侦听器不起作用

时间:2014-12-03 08:50:57

标签: android android-listfragment

我的代码似乎工作得很好,但几天后我注意到该项目单击侦听器停止侦听。我注意到gatListView()没有得到列表..什么可能出错? 这是我的代码:

public class NewsFragment extends ListFragment {


    private NewsFragment local;
    public static final String IMAGE_RESOURCE_ID = "iconResourceID";
    public static final String ITEM_NAME = "itemName";
    public LinearLayout ll;
    public List<RssItem> lri;
    public TextView detail;
    Bitmap bitmap;
    private ListView list;
    private RssParseHandler parsehand;
    ImageLoader imageLoader;

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getListView().setDivider(null);
        list = (ListView)getActivity().findViewById(R.id.list);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        local = this;
        GetRSSDataTask task = new GetRSSDataTask();
        task.execute("........");
        Log.d("ITCRssReader", Thread.currentThread().getName());
    }

    private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem>> {
        @Override
        protected List<RssItem> doInBackground(String... urls) {
            Log.d("ITCRssReader", Thread.currentThread().getName());
            try {
                RssReader rssReader = new RssReader(urls[0]);
                return rssReader.getItems();

            } catch (Exception e) {
                Log.e("ITCRssReader", e.getMessage());
            }
            return null;
        }

        @Override
        protected void onPostExecute(final List<RssItem> result) {

            final ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>    (getActivity(),R.layout.row_site_two, R.id.nameTxt2, result){
            public View getView(int position, View convertView, ViewGroup parent) {

                LayoutInflater inflater = LayoutInflater.from(getActivity());
                convertView = inflater.inflate(R.layout.row_site_two, null, false);

                ImageView left = (ImageView) convertView.findViewById(R.id.img2);
                TextView txt = (TextView) convertView.findViewById(R.id.nameTxt2);
                String bit = result.get(position).getThumb();

                DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                        .cacheOnDisc(true).cacheInMemory(true)
                        .imageScaleType(ImageScaleType.EXACTLY)
                        .displayer(new FadeInBitmapDisplayer(300)).build();

                ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                        getActivity().getApplicationContext())
                        .defaultDisplayImageOptions(defaultOptions)
                        .memoryCache(new WeakMemoryCache())
                        .discCacheSize(100 * 1024 * 1024).build();

                ImageLoader.getInstance().init(config);


                imageLoader = ImageLoader.getInstance();
                DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
                        .cacheOnDisc(true).resetViewBeforeLoading(true)
                        .build();

                Random rnd = new Random();
                // left.setImageAlpha(200);
                // int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
                // left.setColorFilter(color, PorterDuff.Mode.LIGHTEN);

                imageLoader.displayImage(result.get(position).getThumb(), left, defaultOptions);
                txt.setText(result.get(position).getTitle());

                return convertView;
            }

        };


        setListAdapter(adapter);

        ListView listv = getListView();


        listv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String s = adapter.getItem(position).getContent();
                String t = adapter.getItem(position).getTitle();
                String b = adapter.getItem(position).getThumb();



                int pvalue = position;
                Intent i = new Intent(getActivity(), DetailedInfo.class);
                i.putExtra("bitmap", b);
                i.putExtra("pos", "" + s);
                i.putExtra("tit", t);
                startActivity(i);
            }

        });
    }
}

row_site_two.xml:

<ImageView
    android:id="@+id/img2"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:scaleType="fitXY"
    android:clickable="true" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="30dp"
    android:layout_centerHorizontal="true"
    android:background="#4800695c"/>

<TextView
    android:id="@+id/nameTxt2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="30dp"
    android:layout_centerHorizontal="true"
    android:textColor="#ffffffff"
    android:textSize="16dp"
    android:textIsSelectable="true"
     />

1 个答案:

答案 0 :(得分:1)

只需将您的ImageViewTextView关注为假。

 android:focusable="false"
 android:focusableInTouchMode="false"
 android:clickable="false"
row_site_two.xml中的