RSS

Code to handle onclick event of button in listview in Android

05 Sep

Note: Add imlements OnClickListener.

public class MyClass extends Activity implements OnClickListener{
ListView mylist;
private Button btnLoadMessages;
protected void onCreate()
{
mylist = (ListView)findViewById(R.id.listView);
View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.load_messages, null, false);
mylist.addFooterView(footerView);

btnLoadMessages = (Button) footerView.findViewById(R.id.btnLoad);
btnLoadMessages.setOnClickListener(this);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnLoad:
Toast.makeText(this, “You clicked load”, Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}

Advertisements
 
Leave a comment

Posted by on September 5, 2011 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: