0

ListViewルート アクティビティに、クリックされたアイテムに基づいてアクティビティをロードする階層型アプリがあります。ListViewそのアクティビティは、選択などに基づいてアクティビティをロードします。

私の遷移は非常に高速で、遷移アニメーションが終了するとすぐにアクティビティ B が読み込まれます。最も遅い部分は、次のアクティビティへの移行の開始です。

アイテムをクリックすると、トランジション アニメーションが始まる 0.5 秒前です。この遅延の原因は何ですか? onBackPressedを使用して親アクティビティ (single_instance_top、新しいインスタンスまたは再作成されたものではない) に移動する場合にも、同じ遅延が発生します。これは、次の画面が読み込まれる前にユーザーが選択内容の視覚効果を確認できるようにするために組み込まれた遅延ですか?

これが私の活動の1つです。onItemClickメソッドはアダプタから呼び出されListView、その onClick メソッドは何もせず、表示されたメソッドを呼び出します。助言がありますか?

public class Activity_Course extends ActionBarActivity {

    static final String COURSE_ID = "my.COURSE_ID";
    public int courseId;

    public static boolean needsRefresh = false;
    public static boolean isRecreated = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        setContentView(R.layout.activity_course);


        if (savedInstanceState == null) {
            Handler h = new Handler();
            h.post(new Runnable(){
                public void run(){
                    // do your heave tasks
                    Intent intent = getIntent();
                    courseId = intent.getIntExtra(MainFragment.COURSE_ID, 0);
                    getSupportFragmentManager().beginTransaction()
                    .add(R.id.course_activity_frame, new CourseActivityFragment()).commit();
                }
            });
        } else {
            courseId = savedInstanceState.getInt(COURSE_ID);
            Activity_Course.isRecreated = true;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.course, menu);
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {                   
             menu.findItem(R.id.menu_overflow).setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_light);
         }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.edit_course_menu_item) {
            Intent i = new Intent(this, Activity_EditCourse.class);
            i.putExtra(COURSE_ID, courseId);
            startActivity(i);
        } else if(id == R.id.edit_course_gpa_menu_item){
            Intent i = new Intent(this, Activity_EditCourseGPA.class);
            i.putExtra(COURSE_ID, courseId);
            startActivity(i);
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class CourseActivityFragment extends Fragment {

        public final static String GRADE_ID = "my.GRADE_ID";
        public final static String CAT_ID = "my.CAT_ID";
        public final static String COURSE_ID = "my.COURSE_ID";
        public final static String CAT_STRING = "my.CAT_STRING";
        public final static String COURSE_STRING = "my.COURSE_STRING";
        public final static String SEMESTER_STRING = "my.SEMESTER_STRING";

        View rootView;
        int courseId;
        DBAdapter db;
        ScaledGradeHolder gholder;
        ProgressBar pbar;
        ListView categoryListView;
        TextView percentAvg_tv;
        TextView gpa_tv;
        TextView letterGrade_tv;
        Activity curActivity;
        CourseActivityFragment curFrag;
        int gradeColor;
        Course course;
        Adapter_CategoryList catAdapter;
        public final static String CATEGORY_ID = "my.CATEGORY_ID";

        public ArrayList<Category> catList = new ArrayList<Category>();

        public CourseActivityFragment() {
        }

        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setRetainInstance(true);
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            rootView = inflater.inflate(R.layout.fragment_course,
                    container, false);

            db = new DBAdapter(this.getActivity());
            curActivity = this.getActivity();
            curFrag = this;

            if (savedInstanceState != null) {
                courseId = savedInstanceState.getInt(COURSE_ID);

                if(catAdapter != null){
                    catAdapter.clear();
                    catList.clear();
                }

            } else {
                courseId = ((Activity_Course) this.getActivity()).courseId;
            }


            if(Activity_Course.isRecreated){
                if(catAdapter != null)
                    catAdapter.clear();
                Activity_Course.isRecreated = false;
            }


            db.open();
            course = db.getCourse(courseId);
            gholder = db.getScaledCourseGradeHolder(courseId);
            db.close();

            setViews();

            setListData();

            Resources res = getResources();
            categoryListView = (ListView) rootView.findViewById(R.id.cat_list_view);

//                  Applies the adapter to populate the ListView
            catAdapter = new Adapter_CategoryList(curActivity, catList, res, curFrag);
            categoryListView.setAdapter(catAdapter);
            pbar.setVisibility(View.GONE);







            return rootView;
        }

        public void setListData()
        {
            db.open();
            Category[] gt = db.getCategoriesInCourse(courseId);
            db.close();
            if(gt!=null){
                for(int i = 0; i < gt.length; i++) {
                    catList.add(gt[i]);
                }
            }
        }

        public void setViews(){
            // Set header info
            pbar = (ProgressBar)rootView.findViewById(R.id.progressBar1);
            TextView header = (TextView)rootView.findViewById(R.id.course_header);
            header.setText(course.getTitle());
            ((TextView) rootView.findViewById(R.id.semester_header)).setText(course.getSemesterString());

            setGradeSummaryViews();

//          Set column headers of the gradeType ListView
            LinearLayout catHeader = (LinearLayout) rootView.findViewById(R.id.linLayCatheader);
            TextView tv = (TextView)catHeader.findViewById(R.id.category_column);
            TextView tv2 = (TextView)catHeader.findViewById(R.id.weight_column);
            TextView tv3 = (TextView)catHeader.findViewById(R.id.gradecount_column);
            TextView tv4 = (TextView)catHeader.findViewById(R.id.percentage_column);
            tv.setText(R.string.cat_header);
            tv2.setText(R.string.weight_header);
            tv3.setText(R.string.count_header);
            tv4.setText(R.string.percent_header);
        }

        public void setGradeSummaryViews(){
            db.open();
            gholder = db.getScaledCourseGradeHolder(courseId);
            this.getActivity().setTitle(db.getCourse(courseId).getTitle());
            db.close();

            gradeColor = gholder.getColorId();

            // Set gpa
            gpa_tv = (TextView) rootView.findViewById(R.id.gpaGradeTextView);
            gpa_tv.setText(gholder.getGpaGradeString());
            gpa_tv.setTextColor(gradeColor);

            // Set percent average
            percentAvg_tv = (TextView) rootView.findViewById(R.id.percentTextView);
            percentAvg_tv.setText(gholder.getNumberGradeStringPercent());
            percentAvg_tv.setTextColor(gradeColor);

            // Set letter grade
            letterGrade_tv = (TextView) rootView.findViewById(R.id.letterGradeTextView);
            letterGrade_tv.setText(gholder.getLetterGrade());
            letterGrade_tv.setTextColor(gradeColor);
        }

         public void onItemClick(int position){

                Intent i = new Intent(this.getActivity(), Activity_Category.class);
                i.putExtra(CATEGORY_ID, catAdapter.getItem(position).getCategoryId());
                i.putExtra(MainFragment.COURSE_ID, courseId);
                Activity_Category.catId = catAdapter.getItem(position).getCategoryId();
                startActivity(i);


          }

         @Override
            public void onResume(){
                super.onResume();
                if(categoryListView == null)
                    return;
                int cnt = categoryListView.getChildCount();
                for(int i = 0; i < cnt; i++){
                    categoryListView.getChildAt(i).setBackgroundColor(0x00000000);
                }
                //coursesListView.setAdapter(courseAdapter);
            }

         @Override
         public void onStart(){
             super.onStart();
             if(Activity_Course.needsRefresh){
                    catList.clear();
                    setListData();
                    catAdapter.notifyDataSetChanged();
                    setGradeSummaryViews();
                    Activity_Course.needsRefresh = false;
              }
         }

         @Override
            public void onSaveInstanceState(Bundle outState){
                super.onSaveInstanceState(outState);
                outState.putInt(COURSE_ID, courseId);
            }

    }

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState){
        // Save current CourseId
        savedInstanceState.putInt(COURSE_ID, courseId);

        // Call superclass to save view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
    }

    @Override
    public boolean onNavigateUp() { 
        boolean x = super.onSupportNavigateUp();
        overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
        return x;
    }

}
4

1 に答える 1

1

アクティビティ間の「デフォルト」遷移を変更して、非常に高速な遷移を使用できます。参照:

onCreateまた、できることは少ないonResumeため、読み込み時間は非常に短くなり、ハンドラーでの短い遅延 (50 ~ 100 ミリ秒) の後にデータの読み込みと入力が開始されます。

于 2014-10-28T14:36:06.120 に答える