On Tue, May 31, 2011 at 5:46 PM, Amritesh <[email protected]> wrote:

> I am developing an application which will contain the lists of songs
> every row has play image .On click of this image it should change to a
> green one (like on and off), but if there is another image in
> different row is "on" it should get off.
>
> I am able to find the current position and the previous position of
> the row whose image is "on" but based on the position of the row i am
> not able to get the corresponding imageview  .
> I am trying with the setTag() and getTag() method but  get tag method
> is returning null for me.
>
> Any help would be appreciated.Please bail me out of this.
> below is my code
>
>
> package com.fstech.cslist;
>
> import java.util.ArrayList;
> import java.util.Arrays;
> import java.util.HashMap;
> import java.util.Map;
>
>
>
>
> import android.app.Activity;
> import android.content.Context;
> import android.os.Bundle;
> import android.view.LayoutInflater;
> import android.view.View;
> import android.view.ViewGroup;
> import android.view.View.OnClickListener;
> import android.widget.AdapterView;
> import android.widget.ArrayAdapter;
> import android.widget.ImageView;
> import android.widget.ListView;
> import android.widget.TextView;
> import android.widget.Toast;
> import android.widget.ToggleButton;
>
> public class CustomList extends Activity {
>        ArrayList<String> pname;
>        ListView projectList;
>        private LayoutInflater mInflater;
>         private boolean[] itemToggled;
>         int Position;
>         ImageView play;
>         int size;
>         int previousposn=0;
>                int currentposn=0;
>                int cPosition;
>    /** Called when the activity is first created. */
>    @Override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.main);
>        projectList = (ListView) findViewById(R.id.projectlist);
>        pname = new ArrayList<String>();
>        pname.add("first");
>        pname.add("fssecond");
>        pname.add("third");
>        pname.add("fourth");
>        pname.add("fifthe");
>        pname.add("sixth");
>        mInflater = (LayoutInflater)
> getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>        size  = pname.size();
>        itemToggled = new boolean[pname.size()];
>        Arrays.fill(itemToggled, false);
>        projectList.setAdapter(new ArrayAdapter<String>(this,
> R.layout.list_item,pname){
>                        ArrayList<String> ar =new ArrayList<String>();
>
>                        @Override
>                        public View getView(int position, View convertView,
> ViewGroup
> parent) {
>                                 Position=position;
>                                View row;
>
>                                if (null == convertView) {
>                                        row =
> mInflater.inflate(R.layout.list_item, null);
>                                } else {
>                                        row = convertView;
>                                }
>                                TextView tv = (TextView)
> row.findViewById(android.R.id.text1);
>                                tv.setText(getItem(position));
>
>  play=(ImageView)row.findViewById(R.id.roundplay);
>
>  play.setBackgroundResource(R.drawable.roundplay);
>                                ImageView icon = (ImageView)
> row.findViewById(R.id.icon);
>                                icon.setImageResource(R.drawable.roundplay);
>                                play.setTag(String.valueOf(position));
>                                play.setOnClickListener(new
> OnClickListener() {
>
>                                        @Override
>                                        public void onClick(View v) {
>                                                // TODO Auto-generated
> method stub
>
>
> cPosition=Integer.parseInt(v.getTag().toString());
>                                                 previousposn=currentposn;
>
>  currentposn=cPosition;
>
>                                                View view
> =v.findViewWithTag(v.getTag(Position));
>                                                        //(View)
> play.getTag(1);
>
>                                                if(view!=null)
>                                                System.out.println("Tag is
> not returning object");
>                                                else
>
>  System.out.println("Tag is not returning object");
>                                        }
>
>
>                                });
>
>
>
>
>                                return row;
>                        }
>
>        });
>
>        projectList.setOnItemClickListener(new
> AdapterView.OnItemClickListener() {
>            public void onItemClick(AdapterView<?> listView, View
> itemView, int position, long id) {
>                itemToggled[position] = ! itemToggled[position];
>            }
>        });
>
>    }
> }
>
>
The "itemView" you are getting here corresponds to the whole row's
view(row.xml) i.e, Relativelayout in your case. So, get the imageview you
that you want calling the  "childAt()" with the required index on the
"itemView".





>
> **********************************************row.xml**************************
> <?xml version="1.0" encoding="utf-8"?>
> <RelativeLayout
>  xmlns:android="http://schemas.android.com/apk/res/android";
>  android:layout_width="fill_parent"
>  android:layout_height="fill_parent"
>  android:id="@+id/listrow"
>  >
> <ImageView
> android:id="@+id/icon"
> android:layout_width="80dp"
> android:layout_height="80dp"
> android:paddingLeft="5dp"
> android:paddingRight="2dp"
> android:gravity="center_vertical"
>
> />
> <TextView
> android:id="@+id/text1"
> android:layout_width="wrap_content"
> android:paddingLeft="10dp"
> android:textSize="20sp"
> android:layout_centerVertical="true"
> android:layout_toRightOf="@+id/icon"
> android:layout_height="wrap_content"
> android:textColor="#000000"
> ></TextView>
> <ImageView
>
> android:id="@+id/roundplay"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:layout_centerVertical="true"
> android:layout_alignParentRight="true"
> android:paddingRight="5dp"
>
> ></ImageView>
>
> </RelativeLayout>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to