嗨,我使用視圖尋呼機指標與三個片段,並在我有一個列表視圖,顯示我的SQLite數據庫的內容,但是當我的表添加數據列表視圖doesn顯示他新數據,我在這裏添加的是我的代碼:列表視圖根本不會更新
public class caleryhistory extends SherlockListFragment {
List<calery_lagari> Calery_lagari;
calery_lagari_SQLiteData data;
ArrayAdapter<calery_lagari> adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.calery_history, null);
data = new calery_lagari_SQLiteData(getActivity());
data.open();
Calery_lagari = data.findall();
adapter = new ArrayAdapter<calery_lagari>(getActivity(),
R.layout.listback_layout, Calery_lagari);
adapter.notifyDataSetChanged();
setListAdapter(adapter);
adapter.notifyDataSetChanged();
return v;
}
所以有幫助嗎? 在此先感謝! :)
更新
import java.util.List;
import mr.chag.va.lagar.R;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
public class caleryhistory extends SherlockListFragment {
List<calery_lagari> Calery_lagari;
calery_lagari_SQLiteData data;
ArrayAdapter<calery_lagari> adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.calery_history, null);
return v;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
data = new calery_lagari_SQLiteData(getActivity());
data.open();
Calery_lagari = data.findall();
adapter = new ArrayAdapter<calery_lagari>(getActivity(),
R.layout.listback_layout, Calery_lagari);
adapter.notifyDataSetChanged();
ListView listView = (ListView)view.findViewById(android.R.id.list);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
super.onViewCreated(view, savedInstanceState);
}
}
我的佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="clear"
android:text="clear all" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
謝謝!但仍然不起作用 – Like
它應該......現在正在做什麼? –
我已經將所有的代碼都帶到了onViewCreated Override,但仍然沒有更新列表視圖,只顯示舊數據:( – Like