我是新的在Android这里是我的CustomAdaptor列表视图与搜索选项显示三列没有api只与服务器连接

loading...


0

我是android新手 . 我正在连接服务器Mysql而不使用任何API . 这是我的 MachineSearch 代码 . 在这个 list3.get(position) 给我以前的列表,如没有过滤旧数据 .

Everythings工作得很完美,但是当我搜索时,我得到了以前的 List3 数据 . 在搜索时,我得到了新的过滤数据,但是当我点击时我变老了 . 我必须传递隐藏的两个数据ID和要显示的名称 .

提前致谢

public class MachineSearchList extends AppCompatActivity {

SearchView searchView;
CustomAdaptor adapter;
ArrayList<String> list1;
ArrayList<String> list2;
ArrayList<String> list3;
ListView listView;
String dataItemName;
String dataItemId;

ArrayList<SearchSetterandGetter> arrayList = new ArrayList<SearchSetterandGetter>();

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.employeelist_main);
    super.onCreate(savedInstanceState);

    listView = (ListView) findViewById(R.id.listemp);
    searchList();

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            dataItemName = list3.get(position);
            dataItemId = list2.get(position);
            openActivityOne();
        }
    });

    searchView = (SearchView) findViewById(R.id.searchview_lay_act_xml);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.filter(newText);
            return false;
        }
    });

}

public void searchList() {
    try {
        ArrayList<MachineSetterGetter> machineList = null;
        MachineSearch emp = new MachineSearch();
        machineList = emp.getmachineSearch();
        list1 = new ArrayList<>();
        list2 = new ArrayList<>();
        list3 = new ArrayList<>();

        for (MachineSetterGetter machine : machineList) {
            list1.add(machine.getiTemId());
            list2.add(machine.getiTemCode());
            list3.add(machine.getiTemName());
        }

        for (int i = 0; i < list1.size(); i++) {
            SearchSetterandGetter model = new SearchSetterandGetter(list1.get(i), list2.get(i), list3.get(i));
            arrayList.add(model);
        }

        adapter = new CustomAdaptor(getApplicationContext(), arrayList);
        listView.setAdapter(adapter);
        listView.setTextFilterEnabled(true);

    } catch (Exception exh) {

        Log.e("******************", "check" + exh);
    }
}

public void openActivityOne() {
    Intent resultIntend = new Intent();
    resultIntend.putExtra("result", dataItemName);
    resultIntend.putExtra("hideId", dataItemId);
    setResult(RESULT_OK, resultIntend);
    finish();

}

}

我的定制适配器

public class CustomAdaptor extends BaseAdapter  {

Context applicationContext;
LayoutInflater inflater;
ArrayList<String> dataa1;

ArrayList<String> dataa2;

ArrayList<String> dataa3;
ArrayList<String> dataa3Search;

ArrayList<SearchSetterandGetter> modelList;
ArrayList<SearchSetterandGetter> arrayList;

public String getId;
public String getCode;
public String getName;

public CustomAdaptor(Context pplicationContext, ArrayList<SearchSetterandGetter> model) {
    applicationContext=pplicationContext;
    this.modelList=model;

    this.arrayList = new ArrayList<SearchSetterandGetter>();
    this.arrayList.addAll(modelList);
    inflater = (LayoutInflater.from(applicationContext));

}


@Override
public int getCount() {
    return modelList.size();
}

@Override
public Object getItem(int position) {
    return modelList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    convertView = inflater.inflate(R.layout.employeeview_no_name, null);
     TextView emp1 = (TextView) convertView.findViewById(R.id.empname1);
     TextView emp2 = (TextView) convertView.findViewById(R.id.empname2);
     TextView emp3 = (TextView) convertView.findViewById(R.id.empname3);


    emp1.setText(modelList.get(position).getSno());
    emp2.setText(modelList.get(position).getScode());
    emp3.setText(modelList.get(position).getSearchName());


    return convertView;
}


public void filter(String charText){
    charText = charText.toLowerCase(Locale.getDefault());

    modelList.clear();
    if (charText.length()==0){
        modelList.addAll(arrayList);
    }
    else {
        for ( SearchSetterandGetter model  : arrayList){
            if (model.getSearchName().toLowerCase(Locale.getDefault()).contains(charText)||model.getSno().toLowerCase(Locale.getDefault()).contains(charText)){
                modelList.add(model);
            }
        }
    }
    notifyDataSetChanged();
   // modelList.clear();
}

}

loading...

1回答

  • 0

    据我所知你的适配器没有更新,试试这个 . 尝试调试并检查是否更新

    if(adapter !=null){
    adapter = null;
    }
    adapter = new CustomAdaptor(this, arrayList);
            listView.setAdapter(adapter);
            listView.setTextFilterEnabled(true);
    listView.notifyDataSetChanged();
    
评论

暂时没有评论!