0

私はAndroidタブレット用に開発しています.1つのタブは、いくつかの色付きの円のビューを含むいくつかのViewGroups(LinearLayouts)を持つフラグメントであり、それらにはいくつかのデータオブジェクトが関連付けられています。(スクリーンショットを参照)

ネットワークからメッセージが届き、各サークル ビューに関連付けられたデータ オブジェクトの数が更新されます。それらが入ってきたら、それらを SQLite DB に追加したいと思います。その変更がリスニング ViewGroup を自動的に更新すると、これにより、各 CircleView に関連付けられたデータ オブジェクトの数と内容が更新されます。

私はコンテンツプロバイダー、アダプターなどを調べてきました..しかし、これらは電話などの画面全体を占めるリストビュー向けのようです. 質問は、DB の変更に基づいてフラグメント内でこれらのビューを自動的に効率的に更新するにはどうすればよいですか? どのメカニズムを使用し、どのように使用するか。私は多くの行き止まりに来ています。(私の限られたアンドロイド開発経験に基づく)

どんな洞察も素晴らしいでしょう!ありがとう

ビューを設定するタブフラグメント:

    public class TheoryFragment extends Fragment {


    private ViewGroup theoriesView;
    private HashMap<String, TheoryPlanetView> theoryViewsToAnchors = new HashMap<String, TheoryPlanetView>();
    private GestureDetector gestureDetector;    
    private SimpleCursorAdapter dataAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        theoriesView = (ViewGroup) inflater.inflate(R.layout.theories_activity_vertical,
                container, false);

        setupListeners();

        return theoriesView;
    }

    /**
     * Setups the listeners 
     */
    private void setupListeners() {
        //add listeners to all the draggable planetViews
        // get all the colors and the
        int childCount = theoriesView.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View possibleView = theoriesView.getChildAt(i);
            if( possibleView instanceof TheoryPlanetView ) {
                TheoryPlanetView tv = (TheoryPlanetView) possibleView;
                tv.setOnDragListener(new TargetViewDragListener());

                theoryViewsToAnchors.put(tv.getAnchor(), tv);
            }
        }

        ViewGroup planetColorsView = (FrameLayout)             theoriesView.findViewById(R.id.colors_include);
        // get all the colors and the
        childCount = planetColorsView.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View color = planetColorsView.getChildAt(i);
            color.setOnTouchListener(new CircleViewDefaultTouchListener());
        }
    }

}

スクリーンショット

4

1 に答える 1

0

質問を理解するのに苦労しましたが、非同期タスク http://developer.android.com/reference/android/os/AsyncTask.htmlを使用します

基本的に、バックグラウンド スレッドでネットワークまたはデータベースの処理を行います。タスクが完了すると、アンドロイドはメソッドを自動実行します

onPreexecute() -> プログレスバーなどを開始する

doInBackground() -> ネットワーク/データベース

onPostExecute() -> UI を更新します (doInBackground が完了すると呼び出されます)

これで十分でない場合は、オブザーバー パターンを調べることもできます

于 2013-08-13T00:54:17.920 に答える