简体   繁体   English

ListItem Click不起作用

[英]ListItem Click doesn't work

In my code i want to show webview and textview in a list from Rss feed.Here is the code: 在我的代码中,我想在Rss feed的列表中显示webview和textview。这是代码:

 public class VediolistfetchActivity extends Activity {
        /** Called when the activity is first created. */

        ListView Feed;
        URL url;
        String[] title = { " " }, image={""};
        ArrayAdapter<String> adapter;
        ArrayList<Home> homes = new ArrayList<Home>();


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            Feed = (ListView) findViewById(R.id.list);


            try {

                SAXParserFactory saxPF = SAXParserFactory.newInstance();
                SAXParser saxP = saxPF.newSAXParser();
                XMLReader xmlR = saxP.getXMLReader();

                url = new URL("http://www.powergroupbd.com/sweethome/videolist.xml");

                RSSHandler myXMLHandler = new RSSHandler();
                xmlR.setContentHandler(myXMLHandler);
                xmlR.parse(new InputSource(url.openStream()));

                ArrayList<String> GOTTitle = myXMLHandler.gotTitle();
                ArrayList<String> GOTImage = myXMLHandler.gotImage();

                title = new String[GOTTitle.size()];
                image = new String[GOTImage.size()];

                for (int i = 0; i < GOTTitle.size(); i++) {
                    Home home = new Home();
                    title[i] = GOTTitle.get(i).toString();
                    image[i] = GOTImage.get(i).toString();
                    home.openclose=GOTTitle.get(i);
                    home.imagehome=GOTImage.get(i);
                    homes.add(home);
                }

                HomeAdapter homeAdapter = new HomeAdapter(
                        VediolistfetchActivity.this, R.layout.list_catagory,
                        homes);

                Feed.setAdapter(homeAdapter);

            }

            catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "Something Went Wrong, Please check your net connection",
                        Toast.LENGTH_LONG).show();
            }
        }
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub

            Log.i("List Click", "Yes");
            String dtlHomeTitle = Feed.getItemAtPosition(arg2).toString();
            Log.i("title", dtlHomeTitle);


        }


    }

Here is my main.xml: 这是我的main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<ListView
                    android:id="@id/list"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:divider="#000000"
                    android:scrollbars="none"
                    android:scrollingCache="true" />
</LinearLayout>

And here is listcatagory.xml: 这是listcatagory.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
       <ListView
        android:id="@+id/list"
        android:layout_width="1px"
        android:layout_height="1px"
        android:layout_weight="1" >
    </ListView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:weightSum="100" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="38"
            android:orientation="vertical" >

            <WebView
                android:id="@+id/img"
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:paddingBottom="2dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="2dp"
                android:scaleType="centerCrop"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="15"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#ffffff"
                android:textSize="20dp"
                android:textStyle="bold"
                android:paddingLeft="5dp" />


        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="47"
            android:orientation="vertical" >
        </LinearLayout>
    </LinearLayout>



</LinearLayout>

But when i click the individual listitem nothing is happen..plz anybody tell me why this is happens? 但是,当我单击单个列表项时,什么也没有发生。.plz有人告诉我为什么会发生这种情况吗?

You didn't actually set the onItemClick listener on your ListView 您实际上并未在ListView上设置onItemClick侦听器

try this in your onCreate 在您的onCreate中尝试

Feed = (ListView) findViewById(R.id.list);
Feed.setOnItemClickListener(this);

@edit: noticed you don't actually have your class implement the OnItemClickListener despite creating a method identical to the one you'd implement. @edit:请注意,尽管创建的方法与要实现的方法相同,但实际上并没有使类实现OnItemClickListener。 Make sure you add implements OnItemClickListener to your class declaration 确保将implements OnItemClickListener添加到类声明中

public class VediolistfetchActivity extends Activity implements OnItemClickListener

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM