- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用查看寻呼机(动态)来显示来自服务的数据。它工作正常,但每当我再次调用该服务时, View 寻呼机中的数据需要刷新并使用新数据(来自服务)进行更新。
View 分页器中的所有 fragment 都在用新数据刷新,但是 View 分页器的前两个 fragment 没有用新数据更新,这两个 fragment (第一个和第二个)只显示以前的数据。请任何人帮助我。
我的代码:
充值计划 Activity .java:
public class RechargeplansActivity extends FragmentActivity /*implements RechargePlansFragment.UserInterface*/ {
static final String TAG = RechargeplansActivity.class.getSimpleName();
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
Intent intent;
private ArrayList<String> mPlanNamesList;
private ArrayList<BrowsePlan> mBrowsePlansList;
TextView tx_network;
Dialog message_dialg;
Context context;
String operatorid,circleid;
Map<String, ArrayList<BrowsePlan>> mBrowsePlansMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rechargeplans);
context = this;
intent = getIntent();
setPlan_types(new ArrayList<String>());
setBrowseplans(new ArrayList<BrowsePlan>());
mBrowsePlansMap = new HashMap<String, ArrayList<BrowsePlan>>();
//db = DatabaseHandler.getInstance(getApplicationContext());
initUI();
operatorid=intent.getStringExtra("op_id");
circleid=intent.getStringExtra("cir_id");
executeBrowsePlans();
tx_network.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Browseplans_dialog();
}
});
}
/* It is used for initialization */
private void initUI() {
tx_network = (TextView) findViewById(R.id.tx_network);
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
//iv_back = (ImageView) findViewById(R.id.iv_back);
// Create the adapter that will return a fragment
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
mViewPager.setAdapter(mSectionsPagerAdapter);
}
/* Data getting from the service */
private void executeBrowsePlans() {
ServiceClient serviceClient = ServiceUtil.getServiceClient();
mProgressDialog.show();
serviceClient.getPlans_v2(operatorid, circleid, getshowPlansCallback);
}
/**
* @return the al_browseplans
*/
public ArrayList<BrowsePlan> getBrowseplans(String key) {
if (key == null && !mPlanNamesList.contains(key)) {
return new ArrayList<BrowsePlan>();
}
return mBrowsePlansMap.get(key);
}
/**
* @return the al_browseplans
*/
public ArrayList<BrowsePlan> getBrowseplans() {
return mBrowsePlansList;
}
/**
* @param al_browseplans
* the al_browseplans to set
*/
public void setBrowseplans(ArrayList<BrowsePlan> al_browseplans) {
this.mBrowsePlansList = al_browseplans;
}
protected void traceD(String msg) {
// Log.d(TAG, msg);
}
/**
* @return the plan_types
*/
public ArrayList<String> getPlan_types() {
return mPlanNamesList;
}
/**
* @param plan_types
* the plan_types to set
*/
public void setPlan_types(ArrayList<String> plan_types) {
Log.v("Tag_plantype", "" + plan_types.size());
this.mPlanNamesList = plan_types;
}
Callback<JsonObject> getshowPlansCallback = new Callback<JsonObject>() {
@Override
public void failure(RetrofitError arg0) {
// TODO Auto-generated method stub
dismissProgress();
}
@Override
public void success(JsonObject resultUserInfo, Response arg1) {
traceD(" Browse Plans" + resultUserInfo.toString());
dismissProgress();
// String
// planTypes=resultUserInfo.get("Plantypes").getAsString();
// mPlanNamesList.addAll(Arrays.asList(planTypes.split(",")));
// mSectionsPagerAdapter.notifyDataSetChanged();
if (resultUserInfo.has("Status")) {
String Status = resultUserInfo.get("Status")
.getAsString();
if(Status.equalsIgnoreCase("false")){
dismissProgress();
}
else if(Status.equalsIgnoreCase("true")) {
JsonArray array = resultUserInfo.get("Plans")
.getAsJsonArray();
Type type = new TypeToken<ArrayList<BrowsePlan>>() {
}.getType();
Gson gson = new Gson();
getBrowseplans().addAll(
(Collection<? extends BrowsePlan>) gson.fromJson(array,
type));
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Log.v("TAG_PLANS_1",""+mBrowsePlansList.size());
if (mBrowsePlansList.size() > 0) {
Log.v("TAG_PLANS",""+mBrowsePlansList);
for (BrowsePlan bl : mBrowsePlansList) {
if (mBrowsePlansMap.get(bl.getPlanType()) == null) {
mBrowsePlansMap.put(bl.getPlanType(), new ArrayList<BrowsePlan>());
}
mBrowsePlansMap.get(bl.getPlanType()).add(bl);
//setBrowseplans(mBrowsePlansMap.get(bl.getPlanType()));
Log.v("TAG_PLANS_map", "" + (bl.getPlanType().toString())
);
}
}
// mBrowsePlansList.clear();
for (Map.Entry<String, ArrayList<BrowsePlan>> entry : mBrowsePlansMap.entrySet()) {
mPlanNamesList.add(entry.getKey());
}
return null;
}
protected void onPostExecute(Void result) {
for(BrowsePlan bp: getBrowseplans()){
System.out.println("plan type post execute: "+bp.getPlanType()+"value: "+bp.getPlanValue());
}
// mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// mViewPager.setAdapter(mSectionsPagerAdapter);
mSectionsPagerAdapter.notifyDataSetChanged();
//mViewPager.setCurrentItem(4);
}
;
};
task.execute();
}
}
}
};
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
dismissProgress();
}
/* @Override
public void setBrowsePlansToRefresh(RechargePlansFragment.BrowsePalnsAdapter adapter, ListView listView) {
//adapter = new BrowsePlansAdapter();
}
@Override
public void setData(ArrayList<BrowsePlan> plans) {
mBrowsePlansList.clear();
mBrowsePlansList = plans;
}
*/
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
private boolean doNotifyDataSetChangedOnce = false;
public SectionsPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
// Returns total number of pages
@Override
public int getCount() {
if (doNotifyDataSetChangedOnce) {
doNotifyDataSetChangedOnce = false;
notifyDataSetChanged();
}
return getPlan_types().size();
}
// Returns the fragment to display for that page
@Override
public Fragment getItem(int position) {
return RechargePlansFragment
.newInstance(mPlanNamesList.get(position));
}
// Returns the page title for the top indicator
public CharSequence getPageTitle(int position) {
return getPlan_types().get(position);
}
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
return super.instantiateItem(container, position);
}
@Override
public long getItemId(int position) {
return super.getItemId(position);
}
}
@Override
public void onActivityResult(int arg0, int arg1, Intent arg2) {
setResult(arg1, arg2);
traceD("onActivityResult ");
finish();
super.onActivityResult(arg0, arg1, arg2);
}
void showProgress(int msgID) {
dismissProgress();
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(this);
}
if (mProgressDialog != null && !mProgressDialog.isShowing()) {
mProgressDialog.setMessage(getResources().getString(msgID));
mProgressDialog.show();
}
}
void dismissProgress() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}
@Override
public void onResume() {
super.onResume();
mSectionsPagerAdapter.notifyDataSetChanged();
}
void Browseplans_dialog( ) {
message_dialg = new Dialog(this);
Window window = message_dialg.getWindow();
message_dialg.requestWindowFeature(Window.FEATURE_NO_TITLE);
message_dialg.getWindow().setBackgroundDrawable(new ColorDrawable(0));
message_dialg.setContentView(R.layout.activity_selectdialog);
Button viewplans=(Button)message_dialg.findViewById(R.id.viewplans);
viewplans.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
operatorid = "5";
circleid="1";
mPlanNamesList.clear();
mBrowsePlansList.clear();
mBrowsePlansMap.clear();
executeBrowsePlans();
message_dialg.dismiss();
}
});
window.setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
message_dialg.setCancelable(true);
message_dialg.show();
}
}
RechargePlansFragment.java:
public class RechargePlansFragment extends Fragment {
static final String ARG_KEY = "key";
static final String TAG = RechargePlansFragment.class.getSimpleName();
// Store instance variables
ArrayList<BrowsePlan> mBrowseplans ;//= new ArrayList<BrowsePlan>();
BrowsePalnsAdapter browsePlansAdapter;
ListView lv_browseplans;
View rootView;
static String key;
boolean flag = false;
SharedPreferences m_sharedPreference;
SharedPreferences.Editor m_editor;
static UserInterface objUserInterface;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// objUserInterface = (UserInterface)activity;
}
public interface UserInterface{
public void setBrowsePlansToRefresh(BrowsePalnsAdapter adapter, ListView listView);
// public void setData(ArrayList<BrowsePlan> plans);
}
// newInstance constructor for creating fragment with arguments
public static RechargePlansFragment newInstance(String key) {
RechargePlansFragment fragmentFirst = new RechargePlansFragment();
Bundle args = new Bundle();
args.putString(ARG_KEY, key);
//objUserInterface.setBrowsePlansToRefresh();
fragmentFirst.setArguments(args);
return fragmentFirst;
}
// Store instance variables based on arguments passed
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//((MobeRechargeApplication)getActivity().getApplication()).sendScreenName("Browse Plans");
if (getArguments() != null) {
key = getArguments().getString(ARG_KEY);
}
mBrowseplans = new ArrayList<BrowsePlan>();
mBrowseplans.addAll(((RechargeplansActivity) getActivity()).getBrowseplans(key));
Log.v("TAG_KEYYYYY",""+key + " " +mBrowseplans.size()+ " planvalue " +mBrowseplans.get(0).getPlanValue());
traceD(" key :" + key);
}
void traceD(String msg) {
//Log.d(TAG, msg);
}
// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_browseplans, container,
false);
m_sharedPreference = getActivity().getSharedPreferences("save_details", Context.MODE_PRIVATE);
m_editor = m_sharedPreference.edit();
System.out.println("browse size:" + mBrowseplans.size());
for(int i=0; i<mBrowseplans.size();i++){
System.out.println(" Recharge plan type: "+mBrowseplans.get(i).getPlanType());
}
initUI();
browsePlansAdapter = new BrowsePalnsAdapter(mBrowseplans);
lv_browseplans.setAdapter(browsePlansAdapter);
return rootView;
}
@Override
public void onResume() {
super.onResume();
browsePlansAdapter.notifyDataSetChanged();
}
private void initUI() {
lv_browseplans = (ListView) rootView.findViewById(R.id.lv_browseplans);
}
@SuppressWarnings("hiding")
class BrowsePalnsAdapter extends BaseAdapter {
ArrayList<BrowsePlan> allPlans;
public BrowsePalnsAdapter(ArrayList<BrowsePlan> bplans){
this.allPlans = bplans;
}
@Override
public int getCount() {
return allPlans.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
ViewHolder viewHolder;
Typeface custom_regular = Typeface.createFromAsset(getActivity().getAssets(),
"fonts/OpenSans-Regular.ttf");
if (convertView == null) {
viewHolder = new ViewHolder();
view = LayoutInflater.from(getActivity()).inflate(
R.layout.plans_list_adapter, parent, false);
viewHolder.tx_price = (TextView) view
.findViewById(R.id.planvalue_txt);
viewHolder.tx_talktime = (TextView) view
.findViewById(R.id.plantalktime_txt);
viewHolder.tx_validity = (TextView) view
.findViewById(R.id.planvalidity_txt);
viewHolder.tx_plansdetails = (TextView) view
.findViewById(R.id.plansdetails_txt);
viewHolder.tx_price.setTypeface(custom_regular);
viewHolder.tx_talktime.setTypeface(custom_regular);
viewHolder.tx_validity.setTypeface(custom_regular);
viewHolder.tx_plansdetails.setTypeface(custom_regular);
viewHolder.linear=(LinearLayout) view.findViewById(R.id.linear);
convertView = view;
convertView.setTag(viewHolder);
}
viewHolder = (ViewHolder) convertView.getTag();
// System.out.println("n: "+ bbplans.get(position). );
viewHolder.tx_price.setText("RS." + allPlans.get(position).getPlanValue());
viewHolder.tx_validity.setText(allPlans.get(position)
.getPlanValidity());
viewHolder.tx_plansdetails.setText(allPlans.get(position)
.getPlansDetails());
Log.v("TAG_TALKTIME", "" +allPlans.get(position)
.getPlanTalktime());
viewHolder.tx_talktime.setText(allPlans.get(position)
.getPlanTalktime());
viewHolder.linear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
m_editor.putString("amount", allPlans.get(position).getPlanValue());
m_editor.commit();
getActivity().finish();
}
});
return convertView;
}
}
class ViewHolder {
TextView tx_price, tx_talktime, tx_validity, tx_plansdetails;
LinearLayout linear;
}
}
浏览计划.java:
public class BrowsePlan {
@Expose
private String PlanType;
@Expose
private String PlanValidity;
public String getPlanTalktime() {
return PlanTalktime;
}
public void setPlanTalktime(String planTalktime) {
PlanTalktime = planTalktime;
}
@Expose
private String PlanTalktime;
@Expose
private String PlansDetails;
@Expose
private String RCType;
public String getPlanValue() {
return PlanValue;
}
public void setPlanValue(String planValue) {
PlanValue = planValue;
}
public String getSortOrder() {
return SortOrder;
}
public void setSortOrder(String sortOrder) {
SortOrder = sortOrder;
}
public String getRCType() {
return RCType;
}
public void setRCType(String RCType) {
this.RCType = RCType;
}
public String getPlansDetails() {
return PlansDetails;
}
public void setPlansDetails(String plansDetails) {
PlansDetails = plansDetails;
}
public String getPlanValidity() {
return PlanValidity;
}
public void setPlanValidity(String planValidity) {
PlanValidity = planValidity;
}
public String getPlanType() {
return PlanType;
}
public void setPlanType(String planType) {
PlanType = planType;
}
@Expose
private String PlanValue;
@Expose
private String SortOrder;
}
执行浏览计划();是调用web服务的方法。
最佳答案
只是在 SectionsPagerAdapter 类中更改为 FragmentStatePagerAdapter 而不是 FragmentPagerAdapter
它现在正在工作。
关于android - 当 android 中的数据更改时,查看寻呼机的第一个和第二个 fragment 数据没有更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33012056/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!