Open tiwence opened 9 years ago
How about creating a custom adapter or extending a android-ready one. Then inside the getView() method of your Adapter create the listener that make the changes e.g. in your case ClickListener
I'm doing that to populate SwipeCards with a custom layout, there is the code :
/*
*/
public class MoviesAdapter extends ArrayAdapter
private Context mContext;
public MoviesAdapter(Context context, int resource, List<Movie> objects) {
super(context, resource, objects);
this.mContext = context;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder vh = null;
LayoutInflater mInflater = (LayoutInflater) mContext
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.feed_item, parent, false);
vh = new ViewHolder();
vh.mTimeRemaining = (TextView) convertView.findViewById(R.id.showtimeTimeRemainingTextView);
vh.mPoster = (ImageView) convertView.findViewById(R.id.showtimePoster);
vh.mMovieTitle = (TextView) convertView.findViewById(R.id.showtimeTitleTextView);
vh.mTheaterName = (TextView) convertView.findViewById(R.id.showtimeTheaterTextView);
vh.mOtherShowTimesLayout = (LinearLayout) convertView.findViewById(R.id.movieShowTimesLayout);
vh.showOtherShowTimesButton = (ImageButton) convertView.findViewById(R.id.buttonMoreShowTimes);
convertView.setTag(vh);
}
vh = (ViewHolder) convertView.getTag();
final Movie movie = mNextMovies.get(position);
final ArrayList<ShowTime> sts = mResult.getNextShowtimesByMovieId(movie.id_g);
ShowTime bst = sts.get(0);
if (movie.mBestNextShowtime != null)
bst = movie.mBestNextShowtime;
for (int i = 1; i < sts.size(); i++) {
ShowTime s = sts.get(i);
TextView tv = new TextView(getActivity());
tv.setTextColor(Color.WHITE);
tv.setTextSize(14.0f);
tv.setPadding(5, 5, 5, 5);
tv.setText("OLOLOL" + ApplicationUtils.getTimeString(s.mTimeRemaining) + " " + mResult.mTheaters.get(s.mTheaterId).mName);
vh.mOtherShowTimesLayout.addView(tv);
}
vh.mOtherShowTimesLayout.setVisibility(View.GONE);
vh.mTimeRemaining.setText("" + ApplicationUtils.getTimeString(bst.mTimeRemaining));
vh.mMovieTitle.setText(mResult.mMovies.get(bst.mMovieId).title);
vh.mTheaterName.setText(mResult.mTheaters.get(bst.mTheaterId).mName);
vh.showOtherShowTimesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Clicked : ", "" + ((ViewHolder)mFeedContainer.getSelectedView().getTag()).mMovieTitle.getText());
if ( mFeedContainer.getSelectedView().findViewById(R.id.movieShowTimesLayout).getVisibility() == View.GONE) {
mFeedContainer.getSelectedView().findViewById(R.id.movieShowTimesLayout).setVisibility(View.VISIBLE);
} else {
mFeedContainer.getSelectedView().findViewById(R.id.movieShowTimesLayout).setVisibility(View.GONE);
}
Log.d("Visibility", "" + mFeedContainer.getSelectedView().findViewById(R.id.movieShowTimesLayout).getVisibility());
mFeedContainer.invalidate();
}
});
return convertView;
}
public class ViewHolder {
ImageView mPoster;
TextView mMovieTitle;
TextView mTimeRemaining;
TextView mTheaterName;
LinearLayout mOtherShowTimesLayout;
ImageButton showOtherShowTimesButton;
}
}
Hi,
I try to change a linearlayout visibility contained in the top selected view of my SwipeFlingAdapterView by clicking a button also contained in the the top selected view.
So there in my onClick method :
I try to do a notifyDatasetChanged of my adapter, but the first item is removed when the adapter is set :