如何在ListView
public class MainActivity extends Activity implements OnQueryTextListener,OnItemClickListener {
SQLDatabaseSource db;
List<ThuatNgu> list;
ListView lvHienThi;
CustomListView adapter;
public static String chuoiTimKiemKiem = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvHienThi = (ListView) findViewById(R.id.lvHienThi);
list = new ArrayList<ThuatNgu>();
db = new SQLDatabaseSource(this);
list = db.DanhSach();
setAdapterListView(list);
}
private void setAdapterListView(List<ThuatNgu> list){
adapter = new CustomListView(this, R.layout.custom_layout_listview, list);
lvHienThi.setAdapter(adapter);
***`lvHienThi.setOnClickListener(this);`***
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem item = menu.findItem(R.id.search);
SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(this);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
@Override
public boolean onQueryTextChange(String chuoi) {
list = db.TimKiem(chuoi);
setAdapterListView(list);
adapter.notifyDataSetChanged();
chuoiTimKiemKiem = chuoi;
return true;
}
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onItemClick(AdapterView<?> arg0,View arg1,int arg2, long arg3) {
Toast toast=Toast.makeText(this,"Tot", Toast.LENGTH_SHORT);
toast.show();
}
}
我该如何做到这一点?
答案 0 :(得分:0)
在查看您的代码后,我发现这是问题,尽管您的问题没有说什么。我希望这就是你想要的。
使用此
lvHienThi.setOnItemClickListener(this);