C
C
CeBePHblY2016-06-08 13:55:55
Android
CeBePHblY, 2016-06-08 13:55:55

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);
}
}

No items are added to the ListView (the ListView itself is placed in one of the TabHost tabs). how to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question