I’m working with expandable listview. In that I need to use click-able imageview. I’ve tried following but not working. It gives null pointer exception.
here is my xml and listview adapter. I need to put click event on the imageview. from normal activity onclicklistner works perfact, but gives error if you put that in ExpandableListActivity.
Thanks in advance..
public class ExpList extends ExpandableListActivity
{
// static final String parent_node[] = { "grey", "blue", "yellow", "red" };
String parent_node[];
static final String shades[][] = {
{
"lightgrey","#D3D3D3",
"dimgray","#696969",
"sgi gray 92","#EAEAEA"
}, {},
{
"dodgerblue 2","#1C86EE",
"steelblue 2","#5CACEE",
"powderblue","#B0E0E6"
}, {}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
LayoutInflater group_inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View group_layout = group_inflater.inflate(R.layout.group_row, null);
ImageView img_call = (ImageView)group_layout.findViewById(R.id.imgcall);
img_call.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(getBaseContext(), "clicked...", Toast.LENGTH_SHORT).show();
});
SimpleExpandableListAdapterWithEmptyGroups expListAdapter =
new SimpleExpandableListAdapterWithEmptyGroups(
this,
createGroupList(),
R.layout.group_row,
new String[] { "colorName" },
new int[] { R.id.groupname },
createChildList(),
R.layout.child_row,
new String[] { "shadeName", "rgb" },
new int[] { R.id.childname, R.id.rgb }
);
setListAdapter( expListAdapter );}
And my groupview xml is:
<?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="wrap_content"
android:orientation="horizontal">
<ImageView
android:src="@drawable/expander_group"
android:id="@+id/explist_indicator"
android:layout_width="35px"
android:layout_height="35px"/>
<ImageView
android:src="@drawable/contact_thumbnail"
android:id="@+id/img_contact_thumbnail"
android:layout_width="50px"
android:layout_height="50px"/>
<TextView
android:id="@+id/groupname"
android:layout_width="190px"
android:layout_height="match_parent"
android:paddingLeft="30px"
android:textSize="16px"
android:textStyle="bold" />
<ImageView
android:id="@+id/imgcall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/call"
android:clickable="true" />
</LinearLayout>
EDIT
Now NullPointerException problem is solved. But I came up new problem that onclicklistner is not working. No Toast or anything else written in that section doesn’t execute. I debug program and found that code does not return on onclicklistner when imageview get clicked.
Any idea??
You can try this, hope fully it should work. Just add two line in your xml inside imageview and then write a function to listen the button click in your activity class:
And in your activity class :