我试图从SQLite数据库中自动填充TextView自动填充的文本,但是当收入telTrans.setAdapter(适配器)选项卡为空时。 FragmentPageAdapter代码是
public class SectionsPagerAdapter extends FragmentPagerAdapter {
final int NUM_ITEMS = 4;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public CharSequence getPageTitle(int position) {
String tabLabel = null;
switch (position) {
case 0:
tabLabel = getString(R.string.title_section2);
break;
case 1:
tabLabel = getString(R.string.title_section3);
break;
case 2:
tabLabel = getString(R.string.title_section4);
break;
case 3:
tabLabel = getString(R.string.title_section5);
break;
}
return tabLabel;
}
}
片段代码是
public static class DummySectionFragment extends Fragment {
private SQLiteDatabase db;
String[] itemsTelefono;
String[] itemsCliente;
AutoCompleteTextView telTrans;
public static final String ARG_SECTION_NUMBER = "section_number";
public int position;
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
position = args.getInt(ARG_SECTION_NUMBER);
int tabLayout = 0;
switch(position){
case 0:
tabLayout = R.layout.reportes;
break;
case 1:
tabLayout = R.layout.datosmantenimiento;
break;
case 2:
tabLayout = R.layout.repuestos;
break;
case 3:
tabLayout = R.layout.transporte;
break;
}
View rootView = inflater.inflate(tabLayout,container,false);
ConexionSQL usdbh = new ConexionSQL(getActivity(), "DBUsuarios", null, 1);
db = usdbh.getWritableDatabase();
itemsTelefono = usdbh.getAllTelefonos(db);
itemsCliente = usdbh.getAllClientes(db);
telTrans = (AutoCompleteTextView)rootView.findViewById(R.id.txtTelefonoTransporte);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, itemsTelefono);
telTrans.setAdapter(adapter);
return rootView;
}
}
访问数据库没有问题。 当我评论telTrans.setAdapter(适配器)时,标签工作正常但是当它没有评论时显示:
Exception dispatching input event.
Exception in MessageQueue callback: handleReceiveCallback
java.lang.IllegalStateException: Recursive entry to executePendingTransactions