Answer the question
In order to leave comments, you need to log in
Why is ListView not responding to button click?
In the console, you can see that names is changing, but nothing happens on the emulator
public class MainActivity extends Activity {
private int count = 1;
private Button addOne;
String[] names = {"0", "00", "000"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lvPyramid = (ListView) findViewById(R.id.lvPyramid);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);
lvPyramid.setAdapter(adapter);
addOne = findViewById(R.id.b_addOne);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (String name : names) {
String number = name.substring(0, 1);
String nextNumber = Integer.toString(count);
name = name.replace(number, nextNumber);
}
count++;
if (count == 10) count = 0;
}
};
addOne.setOnClickListener(onClickListener);
}
}
Answer the question
In order to leave comments, you need to log in
In the console, you can see that names is changing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question