Answer the question
In order to leave comments, you need to log in
Android. How to add items to ListView from BroadcastReceiver?
doing so
public class AddNewRequestActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
// создаем BroadcastReceiver
br = new BroadcastReceiver() {
// действия при получении сообщений
public void onReceive(Context context, Intent intent) {
String[] names = { "Иван", "Марья", "Петр", "Антон", "Даша", "Борис",
"Костя", "Игорь", "Анна", "Денис", "Андрей" };
// находим список
ListView lvMain = (ListView) findViewById(R.id.listViewRequests);
// создаем адаптер
ArrayAdapter<String> adapter = new ArrayAdapter<String>(AddNewRequestActivity.this, android.R.layout.simple_list_item_1, names);
// присваиваем адаптер списку
lvMain.setAdapter(adapter);
}
};
// создаем фильтр для BroadcastReceiver
IntentFilter intFilt = new IntentFilter(BROADCAST_ACTION);
// регистрируем (включаем) BroadcastReceiver
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