2015-09-29 23 views
0

我收到上述错误消息当我点击图像按钮。我不知道这个问题是在这里。所有我试图做的是采取在文本框中的广告份额它的文本。错误消息:java.lang.NoSuchMethodException:致onClickShare [类android.view.View]

XML

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dip"> 

     <TextView 
      android:id="@+id/txtTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textStyle="normal|bold" 
      android:textSize="16dip" 
      android:padding="5dip" 
      android:text="Title" 
      android:textColor="#001a90" /> 

     <TextView 
      android:id="@+id/txtDescription" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:textSize="18dip" 
      android:padding="5dip" 
      android:text="Description" 
      android:textColor="#000000" 
      android:textIsSelectable="false" /> 

     <ImageButton 
      android:layout_width="25dp" 
      android:layout_height="25dp" 
      android:id="@+id/imageButton8" 
      android:layout_gravity="center_horizontal" 
      android:onClick="onClickShare" /> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:id="@+id/separator1" 
      android:visibility="visible" 
      android:background="@android:color/darker_gray"/> 

    </LinearLayout> 

的Java

​​
+1

您是否对多个活动使用相同的布局? – Blackbelt

+0

唯一的其他用途,在呼叫从显示的项目不同的活性相同的布局。这可能是问题吗?这是呼叫'rssadaptor =新RSSListAdaptor(rssfeed.this,R.layout.rssitemview,ITEMLIST,则params [0]);初始化的ImageButton – Mohammed

+0

尝试,你需要声明'公共无效onClickShare(查看视图)在'每次活动你在哪里设置,布局 –

回答

0

对此的解决办法是添加OnClickListner的getView类ListAdaptor内。

public View getView(int position, View convertView, ViewGroup parent) { 
      View view = convertView; 
      ImageButton whBtn = null; 
      ImageButton fbBtn = null; 
      ImageButton twBtn = null; 

      if(null == view) 
      { 
       LayoutInflater vi = (LayoutInflater)rssfeedFragment.this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       view = vi.inflate(R.layout.rssitemview, null); 
       whBtn = (ImageButton) view.findViewById(R.id.whBtn); 
       fbBtn = (ImageButton) view.findViewById(R.id.fbBtn); 
       twBtn = (ImageButton) view.findViewById(R.id.twBtn); 
      } 

      if (whBtn != null) { 
       whBtn.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         //Code goes here 
         } 
        } 
       }); 
      } 

      if (fbBtn != null) { 
       fbBtn.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         //Code goes here 
         } 
        } 
       }); 
      } 

      if (twBtn != null) { 
       twBtn.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         //Code goes here 
         } 
        } 
       }); 
      }