标签缓慢/滞后

时间:2014-12-11 00:46:35

标签: java android

所以我有3个标签,我注意到我的标签很慢。如何改善选项卡的性能?选项卡具有列表视图。

有哪些方法可以提高标签的效果

我认为问题是因为我有一个带有数据库的列表视图,并且它一直在调用onActivityCreated并且列表正在更新(我不确定)

这是我的代码,这个片段引起了问题

public class Jornal extends Fragment {

DataBasaJurnal dbJ;
ListView listView;
public static myAdapter myA;
ImageButton AddButton;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    View view = inflater
            .inflate(R.layout.fragment_jornal, container, false);



    return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    AddButton = (ImageButton) getActivity().findViewById(R.id.buttonAddJornal);
    AddButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddToJornal.class));

        }
    });

    listView = (ListView) getView().findViewById(R.id.listViewJurnal);
    dbJ = new DataBasaJurnal(getActivity());
    dbJ.open();

    new Handler().post(new Runnable() {
        @Override
        public void run() {
            myA = new myAdapter(getActivity(), dbJ.getAllRowre());
            listView.setAdapter(myA);
        }
    });
    listView.setAdapter(myA);

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            // TODO Auto-generated method stub

            int mySuperInt = dbJ.countCases() - position;
            Intent myIntent = new Intent(getActivity(),
                    JornalListViewClick.class);
            myIntent.putExtra("intVariableName", mySuperInt);
            listView.setEnabled(false);


                startActivity(myIntent);


        }
    });

    }



@Override
public void onStart() {
    // TODO Auto-generated method stub
    super.onStart();

    onActivityCreated(null);

    System.out.println("ok");
    listView.setEnabled(true);



}

class myAdapter extends CursorAdapter {

public myAdapter(Context context, Cursor c) {
    super(context, c);
    // TODO Auto-generated constructor stub
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {

    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View retView = inflater.inflate(R.layout.single_row_jornal, parent,
            false);

    return retView;
}

@Override
public void bindView(View view, Context context, Cursor cursor) {

    TextView textViewMonth = (TextView) view
            .findViewById(R.id.textViewDateWeek);
    textViewMonth.setText(cursor.getString(cursor.getColumnIndex(cursor
            .getColumnName(1))));
    TextView textViewMonthDay = (TextView) view
            .findViewById(R.id.textViewDateNum);
    textViewMonthDay.setText(cursor.getString(cursor.getColumnIndex(cursor
            .getColumnName(2))));
    TextView textViewUserInput = (TextView) view
            .findViewById(R.id.textViewUserInput);
    textViewUserInput.setText(cursor.getString(cursor.getColumnIndex(cursor
            .getColumnName(5))));
    TextView textViewUserTitle = (TextView) view
            .findViewById(R.id.textViewTitelFromDB);
    textViewUserTitle.setText(cursor.getString(cursor.getColumnIndex(cursor
            .getColumnName(6))));
    TextView textViewLucid = (TextView) view
            .findViewById(R.id.textViewhasLucid);



}

}}

0 个答案:

没有答案