I have a problem in this code. It is working and giving me IP addresses already checked. I want to put checkboxes which I can choose from one or more than one IP address. Look at the image under the code below: enter image description
btnScan = (Button)findViewById(R.id.scan);
listViewIp = (ListView)findViewById(R.id.listviewip);
ipList = new ArrayList();
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, android.R.id.text1, ipList);
listViewIp.setAdapter(adapter);
btnScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ScanIpTask().execute();
}
});
This will stop the button from being clickable before you can select an item and only allow button click after item is selected
btnScan = (Button) findViewById(R.id.scan);
listViewIp = (ListView) findViewById(R.id.listviewip);
btnScan.setEnabled(false);
ipList = new ArrayList();
adapter = new ArrayAdapter < String > (this,
android.R.layout.simple_list_item_checked, android.R.id.text1, ipList);
listViewIp.setAdapter(adapter);
listViewIp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView << ? > adapterView, View view, int position, long l) {
btnScan.setEnabled(true);
CheckBox yourCB = findViewById(R.id.yourCB);
yourCB.setClickable(false);
}
@Override
public void onNothingSelected(AdapterView << ? > adapterView) {
}
});
btnScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ScanIpTask().execute();
}
});
EDIT: After reviewing your replies in the comments and your code you will need to use
parent.getItemAtPosition(position).getId()
Which will allow you to get the selected item.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.