I have one listview.which contain one image ,text and one button .i had creted custom listview for that.now i want to change background image of button when button is clicked.i got an click event in getView method of my CustomAdapter.but i m not able to change the background image.
please help me.
following is my code of getView() method of adapter.
public View getView(final int position, View convertView, ViewGroup parent)
{
View v = convertView;
ViewHolder holder = null;
v = vi.inflate(R.layout.row_lv_operator, null);
tvOperatorname=(TextView) v.findViewById(R.id.tvOperatorName);
ivOperatorIcon=(ImageView)v.findViewById(R.id.ivOperatorIcon);
btnAddToFavourite=(Button)v.findViewById(R.id.btnFavourite);
tvOperatorname.setText(values[position]);
ivOperatorIcon.setImageResource(icons[position]);
//holder.ivOperatorIcon.setTag(values[position]);
btnAddToFavourite.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
**btnAddToFavourite.setBackgroundDrawable(getResources().getDrawable(R.drawable.favourite_marked));**
Toast.makeText(getApplicationContext(), "hi",Toast.LENGTH_SHORT).show();
}
});
eturn v;
}
I believe what your trying to do is something like
well.. if im not mistaken View class also have setBackgroundDrawable but the idea is you should use the onclicked view and not the general btnAddToFavourite