I have posted this question before but was unable to resolve the issue as of now. How can we force list view items to be auto clicked in turn through Button? My goal is to make all items in the list view be clickable in turn and perform certain actions such s send Whats app message to others. Code of putting Text into Listview is.
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!namesText.getText().toString().isEmpty()){
adapterNames.add(namesText.getText().toString());
namesText.setText("");
adapterNames.notifyDataSetChanged();
}
}
});
Listview Code for Sending Whats app message is:
listNamesId.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> list, View v, int pos, long id) {
// This two lines is for get indexing value of an item
//adapterNames.getItem(pos);
//Toast.makeText(MainActivity.this, "saif = " + pos, Toast.LENGTH_SHORT).show();
//this below code is for getting item text value
View nextItem = listNamesId.getChildAt(pos+1);
if(nextItem != null){
String selectedFromList = (String) (listNamesId.getItemAtPosition(pos));
namesText.setText(selectedFromList);
}
if (namesTexter.getText().toString().trim().length() == 0) {
Toast.makeText(MainActivity.this, "You are missing your destination number!", Toast.LENGTH_SHORT).show();
} else {
//NOTE : please use with country code first 2digits without plus signed
try {
namesTexter.setText(listNamesId.getItemAtPosition(pos).toString());
String mobile = namesTexter.getText().toString();
String msg = textmessage.getText().toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send?phone=" + mobile + "&text=" + msg)));
} catch (Exception e) {
//whatsapp app not install
}
}
}
});