首页 > 代码库 > ListView Item 点击展开隐藏问题
ListView Item 点击展开隐藏问题
public
class
ListAdapter
extends
BaseAdapter {
private
Context mContext;
private
View mLastView;
private
int
mLastPosition;
private
int
mLastVisibility;
public
ListAdapter(Context context) {
this
.mContext = context;
mLastPosition = -
1
;
}
@Override
public
int
getCount() {
return
30
;
}
@Override
public
Object getItem(
int
position) {
return
null
;
}
@Override
public
long
getItemId(
int
position) {
return
0
;
}
@Override
public
View getView(
int
position, View convertView, ViewGroup parent) {
Holder holder;
if
(convertView ==
null
) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.list_item,
null
);
holder =
new
Holder();
holder.textView = (TextView)convertView.findViewById(R.id.textView);
holder.UEFAView = (ImageView)convertView.findViewById(R.id.image_uefa);
holder.mascotView = (ImageView)convertView.findViewById(R.id.image_mascot);
holder.hint = convertView.findViewById(R.id.hint_image);
convertView.setTag(holder);
}
else
{
holder = (Holder) convertView.getTag();
}
if
(mLastPosition == position){
holder.hint.setVisibility(mLastVisibility);
}
else
{
holder.hint.setVisibility(View.GONE);
}
holder.textView.setText(
"Hello,It is "
+ position);
return
convertView;
}
class
Holder {
TextView textView;
ImageView UEFAView;
ImageView mascotView;
View hint;
}
public
void
changeImageVisable(View view,
int
position) {
if
(mLastView !=
null
&& mLastPosition != position ) {
Holder holder = (Holder) mLastView.getTag();
switch
(holder.hint.getVisibility()) {
case
View.VISIBLE:
holder.hint.setVisibility(View.GONE);
mLastVisibility = View.GONE;
break
;
default
:
break
;
}
}
mLastPosition = position;
mLastView = view;
Holder holder = (Holder) view.getTag();
switch
(holder.hint.getVisibility()) {
case
View.GONE:
holder.hint.setVisibility(View.VISIBLE);
mLastVisibility = View.VISIBLE;
break
;
case
View.VISIBLE:
holder.hint.setVisibility(View.GONE);
mLastVisibility = View.GONE;
break
;
}
}
}
12 13 14 15 16 17 18 19 | public class ListViewTestActivity extends Activity implements OnItemClickListener{ private ListView mListView; private ListAdapter mAdapter; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); mListView = (ListView)findViewById(R.id.list); mAdapter = new ListAdapter( this ); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener( this ); } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mAdapter.changeImageVisable(view, position); } } |
ListView Item 点击展开隐藏问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。