I have a Custom ListView with buttons in which one of the buttons (imgBtnSocial) when clicked changes the visibility of a RelativeLayout inside the row. I'm able to control the RelativeLayout visibility of the row in the ListView but it doesn't target the current clicked row.
Here is my adapter:
//Main Listview Adapter
public class EfficientAdapter extends BaseAdapter {
static FragmentActivity act;
public ArrayList<Post> data;
static LayoutInflater inflater = null;
public static ViewHolder holder;
EfficientAdapter(FragmentActivity a, ArrayList<Post> d) {
act = a;
data = d;
inflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return data.toArray().length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return (position == 0) ? 1 : 0;
}
@Override
public int getViewTypeCount() {
return 2;
}
class ViewHolder {
public TextView label;
public TextView body;
public ImageButton imgBtnComment;
public ImageButton imgBtnStar;
public ImageButton imgBtnShare;
ImageButton imgBtnSocial;
RelativeLayout socialBar_rl;
public int position;
}
View vi;
static int pos;
int counter;
DisplayImageOptions options;
int viewMode;
public View getView(int position, View convertView, final ViewGroup parent) {
vi = convertView;
int theType = getItemViewType(position);
if (vi == null) {
holder = new ViewHolder();
vi = inflater.inflate(R.layout.row_card, null);
holder.label = (TextView) vi.findViewById(R.id.title);
holder.body = (TextView) vi.findViewById(R.id.body);
holder.imgBtnComment = (ImageButton) vi
.findViewById(R.id.imageButton1);
holder.imgBtnComment.setFocusable(false);
holder.imgBtnStar = (ImageButton) vi
.findViewById(R.id.imageButton3);
holder.imgBtnStar.setFocusable(false);
holder.imgBtnSocial = (ImageButton) vi
.findViewById(R.id.imageButton4);
holder.imgBtnSocial.setFocusable(false);
holder.socialBar_rl = (RelativeLayout) vi
.findViewById(R.id.newsSocialPopup);
holder.imgBtnShare = (ImageButton) vi
.findViewById(R.id.imageButton2);
holder.imgBtnShare.setFocusable(false);
vi.setTag(holder);
} else
holder = (ViewHolder) vi.getTag();
holder.position = position;
String title = data.get(position).getTitle();
String body = data.get(position).getListDescription();
holder.label.setText(title);
holder.body.setText(body);
// Comments Button
holder.imgBtnComment.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
FragmentViewHome homeFragment = (FragmentViewHome) act
.getSupportFragmentManager().findFragmentByTag(
"homelist");
final int position = homeFragment.listview_t
.getPositionForView((LinearLayout) v
.getParent()) - 2;
Bundle bundle = new Bundle();
bundle.putString("title", data.get(position).getTitle());
bundle.putInt("position", position);
bundle.putString("entity", data.get(position).getUrl());
Intent intent = new Intent(act,
CommentActivity.class);
intent.putExtras(bundle);
act.startActivity(intent);
}
});
// Comments Button
holder.imgBtnShare.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
FragmentViewHome homeFragment = (FragmentViewHome) act
.getSupportFragmentManager().findFragmentByTag(
"homelist");
final int position = homeFragment.listview_t
.getPositionForView((LinearLayout) v
.getParent()) - 2;
Intent shareIntent = new Intent(
android.content.Intent.ACTION_SEND);
// set the type
shareIntent.setType("text/plain");
// add a subject
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,
data.get(position).getUrl());
act.startActivity(Intent.createChooser(
shareIntent, "Compartir en:"));
}
});
holder.imgBtnStar.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new createbookmark(v).execute();
}
});
holder.imgBtnSocial
.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
FragmentViewHome homeFragment = (FragmentViewHome) act
.getSupportFragmentManager()
.findFragmentByTag("homelist");
final int position = homeFragment.listview_t
.getPositionForView((LinearLayout) v
.getParent()) - 2;
View view = parent.getChildAt(position);
RelativeLayout socialrl = (RelativeLayout) view
.findViewById(R.id.newsSocialPopup);
if (socialrl.getVisibility() == View.GONE) {
Animation anim_social = AnimationUtils
.loadAnimation(
act,
R.anim.socialbar_slide_in_left);
socialrl.startAnimation(anim_social);
socialrl.setVisibility(holder.socialBar_rl.VISIBLE);
} else if (socialrl.getVisibility() == View.VISIBLE) {
Animation anim_social = AnimationUtils
.loadAnimation(
act,
R.anim.socialbar_slide_out_right);
socialrl.startAnimation(anim_social);
socialrl.setVisibility(socialrl.GONE);
}
}
});
return vi;
}
Please need help.