Reputation: 135
public class Chanel_Display extends Activity {
// List view
private ListView lv;
// Listview Adapter
ArrayAdapter<String> adapter;
// Search EditText
EditText inputSearch;
// ArrayList for Listview
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chanel__display);
// Listview Data
lv = (ListView) findViewById(R.id.list_view);
inputSearch = (EditText) findViewById(R.id.inputSearch);
// Adding items to listview
adapter = new ArrayAdapter<String>(this, R.layout.list_item,
R.id.product_name, MainActivity.outlets);
lv.setAdapter(adapter);
/**
* Enabling Search Filter
* */
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// When user changed the Text
Chanel_Display.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
}
Here i write above code to display Listview.It works fine Can i use HashMap insted of array.Because i need to get the id of the clicked item.In my code i can only get the value.All i want to do is to take id of the item (it is a string) of List view.
Upvotes: 0
Views: 64
Reputation: 13520
Do you need id or the item? If you need id you can use lv.getItemIdAtPosition(position)
and if you need the item you can use lv.getItemAtPosition(position)
.
Upvotes: 1