我正在開發一個應用程序與swipe fragment
和我的問題是,客戶端需要,如果他們刷過視圖裏面的數據將自動從sqlite表保存例如在視圖中有在輸入EditText
的值後,它內部的EditText
,當它們滑動到另一個視圖或下一個項目時,該值將保存在sqlite table
中。 PLEASE HELP ME插入到SQLITE表上刷卡片段
//PagerFragment.java類,其中i呼籲viewpager從XML
public class PagerFragment extends Fragment {
private List<PageData> data;
private int currentPosition;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_pager, container, false);
ViewPager mViewPager = (ViewPager) v.findViewById(R.id.pager_view);
currentPosition = getArguments().getInt("CURRENT_POSITION");
data = getArguments().getParcelableArrayList("DATA_LIST");
FragmentItemPagerAdapter fragmentItemPagerAdapter = new FragmentItemPagerAdapter(getFragmentManager(), data);
mViewPager.setAdapter(fragmentItemPagerAdapter);
mViewPager.setCurrentItem(currentPosition);
return v;
}
//ListviewAdapter.java
public class ListViewAdapter extends ArrayAdapter<PageData> {
protected List<PageData> data;
protected LayoutInflater inflater;
public ListViewAdapter(Activity activity, int textViewResourceId, List<PageData> objects){
super(activity, textViewResourceId, objects);
data= objects;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.item_list, parent, false);
PageData pd = data.get(position);
TextView tv2 = (TextView)row.findViewById(R.id.cat);
tv2.setText(pd.getCategory());
// TextView tv3 = (TextView)row.findViewById(R.id.desc);
// tv3.setText(pd.getCategory());
return row;
}
}
//FragmentItempagerAdapter.java
public class FragmentItemPagerAdapter extends FragmentStatePagerAdapter {
private List<PageData> data;
public FragmentItemPagerAdapter(FragmentManager fm, List<PageData> data){
super(fm);
this.data = data;
}
@Override
public Fragment getItem(int position) {
Fragment fragment = new PageFragment();
Bundle args = new Bundle();
args.putString(PageFragment.id, data.get(position).getId());
args.putString(PageFragment.cate, data.get(position).getCategory());
args.putString(PageFragment.code, data.get(position).getCode());
args.putString(PageFragment.desk, data.get(position).getDesk());
args.putString(PageFragment.unit, data.get(position).getUnit());
args.putString(PageFragment.quan, data.get(position).getQuantity());
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
return data.size();
}
public static class PageFragment extends Fragment{
public static final String id = "id";
public static final String cate = "category";
public static final String code = "code";
public static final String desk = "description";
public static final String unit = "unit";
public static final String quan = "Quantity";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item, container, false);
((TextView) rootView.findViewById(R.id.item_label2)).setText(
getArguments().getString(cate));
((TextView) rootView.findViewById(R.id.item_label3)).setText(
getArguments().getString(code));
((TextView) rootView.findViewById(R.id.item_label4)).setText(
getArguments().getString(desk));
((TextView) rootView.findViewById(R.id.item_label5)).setText(
getArguments().getString(unit));
((TextView) rootView.findViewById(R.id.item_label6)).setText(
getArguments().getString(quan));
((TextView) rootView.findViewById(R.id.item_label1)).setText(
getArguments().getString(id));
((EditText) rootView.findViewById(R.id.editText2)).setText(
getArguments().getString(quan));
return rootView;
}
}
}
您使用Viewpager來實現此刷卡功能嗎?如果是這樣,請參閱此更改偵聽器。 https://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html –
是的即時通訊使用viewpager和感謝的鏈接,但你可以給我一個例子,但仍然生病嘗試讀取它並儘快給你反饋:) – RaRa
http://stackoverflow.com/questions/30368641/updating-the-contents-on-tab-changed-in-view-pager這個鏈接可能會幫助你的例子。執行您的數據庫操作,而不是此鏈接中提到的網絡操作。 –