0

在我的代码中,我想在 Rss 提要的列表中显示 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);


        }


    }

这是我的 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>

这是 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>

但是当我单击单个列表项时,什么都没有发生..请有人告诉我为什么会发生这种情况?

4

1 回答 1

0

您实际上并没有在 ListView 上设置 onItemClick 侦听器

在你的 onCreate 中试试这个

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

@edit:注意到您实际上并没有让您的类实现 OnItemClickListener 尽管创建了一个与您要实现的方法相同的方法。确保你添加implements OnItemClickListener到你的类声明

public class VediolistfetchActivity extends Activity implements OnItemClickListener
于 2012-04-17T18:40:06.487 回答