ListView
のカスタムがあり、PHPを使用してサーバーからデータを取り込み、うまくいきます。私はリストの更新のためにnotifyDataSetChanged
を持っています。しかし、問題は、サーバー上のデータが変更された場合です。ListView
の更新されたデータを見るためにボタンを押す必要があります。 WhatsAppリストに類似した更新されたリストを表示するには、より良い方法がありますか?は、更新されたListViewをリアルタイムで見るためにボタンを押す必要があります
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seconds);
contlist = (ListView)findViewById(R.id.contlist);
startService(new Intent(this, serv.class));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("firstTime", false)) {
try {
getNumber(seconds.this.getContentResolver());
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstTime", true);
editor.commit();
} else {
musers = (ArrayList<mobstat>) mobstat.listAll(mobstat.class);
descAdapter = new DescAdapter(seconds.this, musers, seconds.this);
contlist.setAdapter(descAdapter);
}
intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_TICK);
seconds.this.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
descAdapter.notifyDataSetChanged();
}
}, intentFilter);
}
私はnotifyDataSetChanged
ためOnCreate
方法でintentfilter
を使用しています。私はOnStart
、OnResume
の方法でインテントフィルタコードを配置しましたが、私は更新されたリストを見るために戻るボタンをクリックする必要があります。更新されたリストをリアルタイムで表示するには?
http://stackoverflow.com/questions/18337536/android-overriding-onbackpressed –
私は、onBackPressedメソッド内でIntentfilterコードを使用したいのですか? – user2269164
はいはい要件によります –