I am trying to figure out the solution for the following listed problem. I have a Listview
generated using Simpleadapter
. When I click on a row in the listview I want to make a Layout with an id colorful
as visible. I am able to do this. But my problem starts here. When I click on another row say row number 5 the colorful layout is visible, but the layout is also visible for the previously clicked row too. What I want to do is make the layout colorful visible for only the clicked row (i.e it should be visible for only one row at a time i.e is currently clicked row and hidden for all the remaining rows) and the layout should get invisible for the previously clicked rows. I tried doing with viewholder
but it doesn't help. My code snippet is below. Guide me step by step as I am very new to Android.
final BaseAdapter k=new SimpleAdapter(getActivity(),val,R.layout.mytaskdata,new String[]{"sname","heading","desc","id","path","receiver","sender"},new int[]{R.id.textView1,R.id.textView2,R.id.textView3,R.id.hide1,R.id.hide2,R.id.hide3,R.id.hide4})
{
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final View v = super.getView(position, convertView, parent);
TextView myname=(TextView)v.findViewById(R.id.textView1);
TextView mydes=(TextView)v.findViewById(R.id.textView2);
TextView mytopic=(TextView)v.findViewById(R.id.textView3);
ImageView edit=(ImageView)v.findViewById(R.id.ImageView03);
sent.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
RelativeLayout r=(RelativeLayout)arg1.findViewById(R.id.colorful);
// r.setVisibility(arg1.VISIBLE);
int temp=sent.getCheckedItemPosition();
Log.i("itemposition",""+temp);
Toast.makeText(getActivity(),"pos"+arg2+"hii"+positionThatSaysHi,1000).show();
if(arg2!=positionThatSaysHi)
{
r.setVisibility(arg1.VISIBLE);
positionThatSaysHi = arg2;
notifyDataSetChanged();
}
else
{
r.setVisibility(arg1.GONE);
notifyDataSetChanged();
}
});