I am developing Android Application. In which i am having list view with text and image. i need to set the imageview visible at run time. ie. when i clicked the view it should appear and when i click next view previous view have to disappear and corresponding imageview in clicking view have to appear.
Now i am success in displaying text but i am strucking in appearance of imageview. Inside the onclick of item list i cannot set the resource for imageview
Below is my code.
public class ListofCategory extends Activity{
ListView listview;
List<String> mycategoryId,mycategoryName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.listofcategory);
listview=(ListView)findViewById(R.id.category_listview);
mycategoryId=new ArrayList<String>();
mycategoryName=new ArrayList<String>();
getData();
listview.setAdapter(new MyListAdapter(this));
//setListAdapter(new MyListAdapter(this));
}
class MyListAdapter extends BaseAdapter{
private Context context;
MyListAdapter(Context context)
{
this.context=context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mycategoryId.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View view, ViewGroup viewgroup) {
ViewHolder holder = null;
LayoutInflater inflater = LayoutInflater.from(context);
if (view == null)
{
view = inflater.inflate(R.layout.mycategorylist, null);
holder = new ViewHolder();
holder.categoryname = (TextView) view.findViewById(R.id.title);
holder.categorycount = (TextView) view.findViewById(R.id.description);
holder.arrow=(ImageView)view.findViewById(R.id.arrow_imageview);
view.setTag(holder);
}
else
{
holder = (ViewHolder) view.getTag();
}
holder.categoryname.setText(mycategoryName.get(position));
holder.categoryname.setTextSize(18.0f);
//holder.arrow.setImageResource(R.drawable.arrow);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
Problem occurs here.. This holder value ask me to change as final but here i cannot make holder to final
holder.arrow.setImageResource(R.drawable.arrow);
//finish();
}
});
return view;
}
}
class ViewHolder
{
TextView categoryname;
TextView categorycount;
ImageView arrow;
}
}
Please anyone give me a better solution..its very urgent.. Thanks in advance
Create a final pointer for the imageView.
than in the onclick:
Added to the class a field:
In the oncreate method do this:
On the onclick event do this:
That should work.