OTAFileAdapter.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.slam.bboxble;
  2. import android.content.Context;
  3. import android.util.Log;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.widget.BaseAdapter;
  8. import android.widget.CheckBox;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. /**
  12. * Created by lenovo on 2017/9/27.
  13. */
  14. public class OTAFileAdapter extends BaseAdapter {
  15. private final String TAG = OTAFileAdapter.class.getSimpleName();
  16. private Context mContext;
  17. private LayoutInflater mInflater;
  18. public static HashMap<Integer, Boolean> isSelected;
  19. private HashMap<String, FileInfo> mOTAFileList = null;
  20. private ArrayList<String> mFileList = null;
  21. public OTAFileAdapter(Context context, HashMap<String, FileInfo> list,
  22. int resource, ArrayList<String> arrayList) {
  23. mContext = context;
  24. mOTAFileList = list;
  25. mFileList = arrayList;
  26. mInflater = LayoutInflater.from(context);
  27. init();
  28. }
  29. public void init() {
  30. isSelected = new HashMap<Integer, Boolean>();
  31. for (int i = 0; i < mOTAFileList.size(); i++) {
  32. isSelected.put(i, false);
  33. }
  34. }
  35. @Override
  36. public int getCount() {
  37. return mOTAFileList.size();
  38. }
  39. @Override
  40. public Object getItem(int position) {
  41. return mOTAFileList.get(mFileList.get(position).toString());
  42. }
  43. @Override
  44. public long getItemId(int position) {
  45. return position;
  46. }
  47. @Override
  48. public View getView(int position, View convertView, ViewGroup parent) {
  49. CheckBox mCheckBox;
  50. if(convertView != null)
  51. {
  52. mCheckBox = (CheckBox) convertView.getTag();
  53. }else
  54. {
  55. convertView = mInflater.inflate(R.layout.listitem_script, null);
  56. mCheckBox = (CheckBox) convertView.findViewById(R.id.script_item);
  57. convertView.setTag(mCheckBox);
  58. }
  59. Log.i(TAG, mFileList.get(position));
  60. mCheckBox.setText(mOTAFileList.get(mFileList.get(position)).getFileName());
  61. mCheckBox.setChecked(isSelected.get(position));
  62. return convertView;
  63. }
  64. public String getCheckedFileName()
  65. {
  66. for(int forCount = 0; forCount < mOTAFileList.size(); forCount++)
  67. {
  68. if(isSelected.get(forCount))
  69. {
  70. String lFileName = mFileList.get(forCount).toString();
  71. return lFileName;
  72. }
  73. }
  74. return null;
  75. }
  76. }