当我滑动SwipeMenuListview项目时,它只显示第一个位置的文本视图,但我想在我滑动列表项时显示所有位置textview的文本。 例如,在我的情况下,当我在列表项上滑动时,我想要4个textview可见。
public class ProfilePersonalDownloadActivity extends AppCompatActivity{
ProfilePersonalDownloadAdapter profilePersonalDownloadAdapter;
@BindView(R.id.lvProfileSongDownloadList)
SwipeMenuListView lvProfileSongDlList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_personal_download);
ButterKnife.bind(this);
profilePersonalDownloadAdapter = new ProfilePersonalDownloadAdapter(ProfilePersonalDownloadActivity.this);
lvProfileSongDlList.setAdapter(profilePersonalDownloadAdapter);
int t_Session = 0;
for (int i = 0, len = profilePersonalDownloadAdapter.getCount(); i < len; i++) { // detailMovieAdapter.getCount()返回数据项的数目
View listItem = profilePersonalDownloadAdapter.getView(i, null, lvProfileSongDlList);
listItem.measure(0, 0); // 计算子项View 的宽高
t_Session += listItem.getMeasuredHeight(); // 统计所有子项的总高度
}
ViewGroup.LayoutParams params1 = lvProfileSongDlList.getLayoutParams();
params1.height = t_Session + (lvProfileSongDlList.getDividerHeight() * (profilePersonalDownloadAdapter.getCount() - 1));
lvProfileSongDlList.setLayoutParams(params1);
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(
getApplicationContext());
// set item background
deleteItem.setBackground(R.color.view_color);
// set item width
deleteItem.setWidth(dp2px(90));
// set a icon
deleteItem.setTitle("Delete");
deleteItem.setIcon(R.drawable.ic_dltrash);
// add to menu
menu.addMenuItem(deleteItem);
}
};
lvProfileSongDlList.setMenuCreator(creator);
// step 2. listener item click event
lvProfileSongDlList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
// ApplicationInfo item = mAppList.get(position);
switch (index) {
case 0:
// delete song
// lvProfileSongDlList.getChildAt(position);
Toast.makeText(ProfilePersonalDownloadActivity.this, "delete song called"/*+position*//*+" "+index*/, Toast.LENGTH_SHORT).show();
// lvProfileSongDlList.removeViewAt(position);
profilePersonalDownloadAdapter.notifyDataSetChanged();
break;
}
return false;
}
});
// set SwipeListener
lvProfileSongDlList.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// swipe start
}
@Override
public void onSwipeEnd(int position) {
// swipe end
}
});
// set MenuStateChangeListener
lvProfileSongDlList.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() {
@Override
public void onMenuOpen(int position) {
for (int i=0;i<profilePersonalDownloadAdapter.getCount();i++){
Log.d("TAG", "onSwipeStart: "+i);
View v = lvProfileSongDlList.getChildAt(i).getRootView();
if (v != null) {
Log.d("TAG", "onMenuOpen: "+"inside if "+i);
TextView tvSongSize = (TextView) v.findViewById(R.id.tvSongSize);
tvSongSize.setVisibility(View.VISIBLE);
}
}
}
@Override
public void onMenuClose(int position) {
for (int i=0;i<profilePersonalDownloadAdapter.getCount();i++){
Log.d("TAG", "onSwipeStart: "+i);
View v = lvProfileSongDlList.getChildAt(i).getRootView();
if (v != null) {
Log.d("TAG", "onMenuOpen: "+"inside if "+i);
TextView tvSongSize = (TextView) v.findViewById(R.id.tvSongSize);
tvSongSize.setVisibility(View.GONE);
}
}
// }
}
});
}
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
}
public class ProfilePersonalDownloadAdapter extends BaseSwipListAdapter{
private LayoutInflater inflater;
private Context mcontext;
ViewHolder holder;
class ViewHolder {
@BindView(R.id.tvSongSize)
TextView tvSongSize;
////
public ViewHolder(View view) {
ButterKnife.bind(this,view);
}
}
public ProfilePersonalDownloadAdapter(/*ArrayList<AddJobModel> tempItemList, */Context context/*, boolean isEditClickedFromOptionMenu*/) {
inflater = null;
// productItemList = tempItemList;
mcontext = context;
inflater = (LayoutInflater) this.mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return 4;
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return (long) i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.row_profile_download_song_list, null);
holder = new ViewHolder(convertView);
convertView.setTag(this.holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
}