问题描述:

so i have 3 tabs and i have noticed that my tabs are slow. how can i improve the performance of the tabs. The tabs have list views.

what are the ways to improve performance for the tabs

i think the problem is because i have a list view with a database and it is constantly calling the onActivityCreated and the list is updating(i m not sure)

here is my code this fragment is causing the problem

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);

}

}}

相关阅读:
Top