public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
CustomerAdapter adapter = null;
ArrayList<Customer> customers = null;
ListView myCustomListView;
SearchView mySearchView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customers = new ArrayList<>();
customers = populateCustomerData(customers);
mySearchView = (SearchView) findViewById(R.id.mySearchView);
myCustomListView = (ListView) findViewById(R.id.myCustomListView);
adapter = new CustomerAdapter(this, customers);
myCustomListView.setAdapter(adapter);
myCustomListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (id ==0) {
Intent intent = new Intent(MainActivity.this, account1.class);
MainActivity.this.startActivity(intent);
}
if(id== 1){
Intent intent1 = new Intent(MainActivity.this, account2.class);
MainActivity.this.startActivity(intent1);
}...
mySearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s)
{
return false;
}
@Override
public boolean onQueryTextChange(String s) {
// Here implement search logic
adapter.getFilter().filter(s);
adapter.notifyDataSetChanged();
return false;
}
});
}
private ArrayList<Customer> populateCustomerData(ArrayList<Customer> customers) {
customers.add(new Customer("조회", 1, R.drawable.account));
customers.add(new Customer("인출", 2, R.drawable.account));
customers.add(new Customer("입금", 3, R.drawable.account));
return customers;
}
}
저렇게 코드를 짰는데요, 처음에 리스트뷰 상태에서 누를 때는 잘 작동 하는데
검색 후 리스트뷰를 누르면 값이 초기화 되더라구요..
이럴때 onclick을 어떻게 구현해야 할까요?
예를들면 검색 시 "입금"을 입력했는데 그 값을 누르면
첫번째 리스트뷰 값인 "조회"가 뜹니다!