0

Im trying to implement instagram like listview , in each row there is like button and also comment box. the question is how can i achieve similar function in listview which means each row is specific and its not repeating for other rows , what i tries is , when a user clicks on button after some item , all other items are clicked! means the clicked item is repeating and its obvious i don't want this! how can i achieve instagram like row

        @Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    viewHolder mHolder;
    if(convertView==null){
        mHolder = new viewHolder();
        convertView = mInflator.inflate(R.layout.row_all_artist, parent, false);
        mHolder.mArtistName = (TextView) convertView.findViewById(R.id.artist_name);
        mHolder.mFollowers = (TextView) convertView.findViewById(R.id.artist_followers);
        mHolder.mFollow = (Button) convertView.findViewById(R.id.artist_follow);
        AppLogic.ChangeTextViewFont(mContext, mHolder.mArtistName);
        convertView.setTag(mHolder);

    } else{
        mHolder = (viewHolder) convertView.getTag();
    }

    mHolder.mArtistName.setText(mItems.get(position).getArtistFullName());
    mHolder.mFollowers.setText(mItems.get(position).getArtistFollowers());
    mHolder.mFollow.setTag(R.id.artist_follow,mItems.get(position).getArtistID());
    mHolder.mFollow.setOnClickListener((OnClickListener) mContext);

    return convertView;
}

EDIT

my question is not about touching items or setting unlike listener or like this! the problem is when i click the button i change its background color , but this color is repeating on every 10 item on the list! there is a related question to me here : ListView repeated CheckBox behavior every 10th item erratically

public void onClick(final View v) {

    if (!AppLogic.isLoggined(mShared)) {
        AppLogic.ToastMaker(getApplicationContext(),
                getResources().getString(R.string.msg_loginError));
        startActivity(new Intent(FirstTimePage.this, Register.class)
                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

    } else {

        AppLogic.doFollow(FirstTimePage.this, v, mShared);
    }
}
Community
  • 1
  • 1
Mahdi Giveie
  • 630
  • 1
  • 8
  • 25

3 Answers3

1

Prevent getting focus by the button.

Add this to the top element in your row_all_artist.xml custom view

android:descendantFocusability="blocksDescendants"
AterLux
  • 4,566
  • 2
  • 10
  • 13
  • the problem is not the buttons are not clickable! my problem is when i click a button i change its background , but its repeating on every 10 item on listview , like recycle – Mahdi Giveie Jun 02 '15 at 06:50
0

Create a new OnClickListener for every row, or check the View given in the argument at your current listener.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
0

You are setting your mContext as the OnClickListener

mHolder.mFollow.setOnClickListener((OnClickListener) mContext);

You should just implement the ListView method setOnItemClickListener and then check for the position of the item that was clicked. Tags are also very helpful here.

Example: Adding an onclicklistener to listview (android)

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36