Answer the question
In order to leave comments, you need to log in
Why isn't ListView from BroadcastReceiver updated?
I have this code:
public class AddNewRequestActivity extends Activity {
ListView lvMain;
ArrayAdapter<String> adapter;
String[] names = {"Денис", "Андрей"}; //допустим, какие-то начальные данные
protected void onCreate(Bundle savedInstanceState) {
lvMain = (ListView) findViewById(R.id.listViewRequests);
adapter = new ArrayAdapter<String>(AddNewRequestActivity.this, android.R.layout.simple_list_item_1, names);
lvMain.setAdapter(adapter);
br = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String[] newNames = { "Иван", "Марья", "Петр", "Антон", "Даша", "Борис", "Костя", "Игорь", "Анна", "Денис", "Андрей" };
adapter.clear();
adapter.addAll(newNames);
adapter.notifyDataSetChanged();
}
};
IntentFilter intFilt = new IntentFilter(BROADCAST_ACTION);
registerReceiver(br, intFilt);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question