我已使用列表视图实现了自定义复选框。我现在得到列表我想要的包名列表,在获取位置的帮助下检查。如何获得该位置有任何方法可以做到这一点。
class Custom_List extends BaseAdapter {
Activity activity = null;
List<String> app_name = null;
List<String> app_usage = null;
List<String> app_last_updated = null;
List<String> app_cpu_usage = null;
List<String> app_package = null;
public Custom_List(Activity this_activity, List<String> app_name2, List<String> app_usage, List<String> app_last_modi_data, List<String> app_CPU_Usage,List<String> app_package) {
// TODO Auto-generated constructor stub
activity = this_activity;
this.app_name = app_name2;
this.app_usage = app_usage;
this.app_last_updated = app_last_modi_data;
this.app_cpu_usage = app_CPU_Usage;
this.app_package=app_package;
}
public int getCount() {
// TODO Auto-generated method stub
return app_name.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class ViewHolder {
public TextView textheader = null;
public TextView textcpu = null;
public TextView text_modified_date = null;
public TextView text_cpu = null;
public TextView text_checkbox = null;
}
ViewHolder holder = null;
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.grid_item, null);
holder = new ViewHolder();
holder.textheader = (TextView) vi.findViewById(R.id.item1);
holder.textcpu = (TextView) vi.findViewById(R.id.item2);
holder.text_modified_date = (TextView) vi.findViewById(R.id.item4);
holder.text_cpu = (TextView) vi.findViewById(R.id.item3);
holder.text_checkbox=(CheckBox)vi.findViewById(R.id.checkBox1);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
holder.text_checkbox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "coming here", Toast.LENGTH_LONG).show();
String packag=app_package.toString();
Log.d("package listttttttttt", packag);
addListenerOnButton() ;
}
});
holder.textheader.setText(Html.fromHtml(app_name.get(position)).toString());
int usage=Integer.parseInt(app_usage.get(position).toString().trim())/10000;
holder.textcpu.setText("Mem: "+String.valueOf(usage)+" M");
// System.out.println(" app_last_updated "+app_last_updated.get(position).toString().trim());
holder.text_modified_date.setText("Last Updated Date: "+app_last_updated.get(position).toString().trim());
holder.text_cpu.setText("CPU: "+app_cpu_usage.get(position).toString().trim()+" %");
return vi;
}
}
private void addListenerOnButton() {
Clear = (Button) findViewById(R.id.button1);
Clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "coming in button", Toast.LENGTH_LONG).show();
}
});
}
}