I have a listview, whick get its data from a SQLite db. I would like to let user change value of field by click on items. But with following code, the click event is not fired. Could some one help on it? Thanks!
public class BDXDeviceActivity extends Activity {
private DeviceListControl deviceListControl;
private ListView listViewDevice;
private DeviceListAdapter2 deviceListAdapter2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// using a custom layout, otherwise a system default of List
setContentView(R.layout.activity_device_list);
listViewDevice = (ListView) findViewById(R.id.listViewDevice);
deviceListControl = new DeviceListControl(this);
// setListAdapter(new DeviceListAdapter2(this, deviceListControl.getDevices()));
deviceListAdapter2 = new DeviceListAdapter2(this, deviceListControl.getDevices());
listViewDevice.setAdapter(deviceListAdapter2);
listViewDevice.setClickable(true);
listViewDevice.setOnItemClickListener(onItemClickListener);
}
AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(), "clicked", Toast.LENGTH_SHORT).show();
DeviceName deviceName = (DeviceName) listViewDevice.getAdapter().getItem(position);
deviceListControl.deleteDevice(deviceName.getId());
// after delete, reread the list adapter and get names list via namechange
deviceListAdapter2 = new DeviceListAdapter2(getBaseContext(), deviceListControl.getDevices());
listViewDevice.setAdapter(deviceListAdapter2);
// Display success information
Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_LONG).show();
}
};
... layout file
<EditText
android:id="@+id/txtSearchDevice"
android:layout_width="200dp"
android:layout_height="30dp"
android:background="#f7f5b1a3"
android:focusable="false"
/>
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="@+id/btnSearchDevice"
android:textColor="#ff151515"
android:background="@android:drawable/ic_menu_search"
android:focusable="false"/>
</LinearLayout>
<ListView
android:id="@+id/listViewDevice"
android:layout_width="match_parent"
android:layout_height="300dp">
</ListView>