2012-04-17 66 views
0

在我的代碼我想告訴的WebView和TextView的從RSS feed.Here列表是代碼:列表項點擊不起作用

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> 

但是當我點擊個人列表項沒有什麼happen..plz有人告訴我這是爲什麼會發生?

回答

0

你實際上並沒有設置onItemClick聽衆對你的ListView

在你的onCreate

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

@edit試試這個:注意到你實際上並沒有你的類實現OnItemClickListener儘管創建方法與您實施的方法相同。請確保您添加到implements OnItemClickListener類聲明

public class VediolistfetchActivity extends Activity implements OnItemClickListener 
+0

我只是添加OnItemClickLostener在我的代碼就像你說的..和我的我要舉杯當我點擊item..but沒有什麼happend個人名單.. :(@覆蓋 \t公共無效onItemClick(適配器視圖爲arg0,查看ARG1,INT ARG2,長ARG3){ \t \t // TODO自動生成方法存根 \t \t字符串d = Feed.getItemAtPosition(ARG2)的ToString(); \t \t Toast.makeText(getApplicationContext(),d,Toast.LENGTH_LONG).show(); \t} – 2012-04-17 18:55:13

+0

現在我編輯這個像你說..但沒有什麼是烤麪包當我點擊一個單獨的項目.. :( – 2012-04-17 18:57:44

+0

是我添加show ..但什麼都不是烤麪包當我點擊 – 2012-04-17 19:03:51