do 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?

    1 answer 1

    Post an ad in onCreate , and in the BroadcastReceiver just change. Like that:

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