i am populating a set of custom_rows
into my listview
from baseadapter
.
And i set the listview in my fragment.
I am trying to set android:onClick="openComment
to the button which is in my custom_row.xml
but the i get the below error
java.lang.IllegalStateException: Could not find method openComment(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageView with id 'open'
In my Fragment i have the method openComment. How do i call the the method from the button click. This is Fragment shows how i call the method.
public class Home extends android.support.v4.app.Fragment implements View.OnClickListener {
....
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
myview = inflater.inflate(R.layout.home, container,false);
listView = (ListView) myview.findViewById(R.id.activity_main);
return myview;
}
....
....
public void openComment(View v)
{
//getting the position of clicked row
final int position = listView.getPositionForView((View) v.getParent());
System.out,print("button clicked");
}
my custom_row.xml
looks like this. it has a textview and a button
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/open"
android:onClick="openComment"
android:layout_width="45dp"
android:layout_height="45dp"/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Below is my ListView activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/custom_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>