I use ListVew to show several items.
I use the code to list item.
getListView().setEmptyView(findViewById(R.id.empty));
adapter = new MyAdapter(this, FileName, Check);
setListAdapter(MyAdapter);
And while item click, I use below code to refresh.
adapter = new MyAdapter(this, FileName, Check);
setListAdapter(MyAdapter);
FileName and Check are arrays.
But while I click one item, it refresh and the cursor return to top.
After refresh, I want it focus on the clicked one.
How to do it?
MyAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewTag viewTag;
if(convertView == null) {
convertView = myInflater.inflate(R.layout.row_phone_video, null);
viewTag = new ViewTag(
(TextView)convertView.findViewById(R.id.phone_video_name),
(CheckBox)convertView.findViewById(R.id.phone_video_check)
);
convertView.setTag(viewTag);
}
else {
viewTag = (ViewTag) convertView.getTag();
}
viewTag.title.setText(FileName[position]);
viewTag.cbx.setVisibility(View.VISIBLE);
if(Check[position]) {
viewTag.cbx.setChecked(true);
}
else {
viewTag.cbx.setChecked(false);
}
}
return convertView;
}
class ViewTag {
TextView title;
CheckBox cbx;
public ViewTag(TextView tv, CheckBox cb) {
this.title = tv;
this.cbx = cb;
}
}
Check this
This code will work if the user clicks the check box. Inside the getView function instead of checkbox click copy paste the code into converview’s onclick listener.