我在操作栏中有一个带有计数通知的购物篮图标,用于显示购物篮中的商品数量。我还有一个自定义视图,其中包含一个用于将商品添加到购物篮的按钮。我希望当我点击按钮(在自定义视图中)时,篮子图标上的通知计数会增加。我在主要活动中使用此功能来更新通知计数,但通知不会更新。
public static void updateCountBasket(final int number , int id , View view ,Context context) {
if (view.findViewById(id) == null)
return;
TextView t = (TextView)view.findViewById(id);
String dd = t.getText().toString();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (number == 0)
t.setVisibility(View.INVISIBLE);
else {
t.setVisibility(View.VISIBLE);
t.setText(Integer.toString(number));
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
但是当我在主要活动中使用该功能的非静态并单击简单按钮时,它工作正常。但我也不能在基本适配器中调用非静态函数:(。我在静态模式下逐行检查了函数的所有 id 都是正确的,它也设置了文本,但没有任何更改或出错!!请帮我更改当单击自定义视图中的按钮时,textview 作为基本适配器菜单栏中篮子的通知。谢谢我有这个基本适配器用于我的自定义视图列表:
public class Goods_ImageAdapter extends BaseAdapter {
private Context context;
private final JSONArray Goods;
private Bagde bagde;
public Goods_ImageAdapter(Context context , JSONArray Goods) {
this.context = …Run Code Online (Sandbox Code Playgroud) 我使用代码 A 创建一个带有单选按钮的 RecyclerView,该按钮基于从网站搜索到的一些示例代码。
\n\n1\xe3\x80\x81不知道这些代码好不好,有没有更好的方法在RecyclerView中实现单选按钮?
\n\n2\xe3\x80\x81如何设置启动APP时默认选中的第一个单选按钮?你知道,当我启动应用程序时,没有选中任何单选按钮。
\n\n代码A
\n\nclass CustomAdapter (val backupItemList: List<MSetting>) : RecyclerView.Adapter<CustomAdapter.ViewHolder>() {\n\n private var mSelectedItem = -1\n\n override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomAdapter.ViewHolder {\n val v = LayoutInflater.from(parent.context).inflate(R.layout.item_recyclerview, parent, false)\n return ViewHolder(v)\n }\n\n fun getSelectedItem():Int{\n return mSelectedItem\n }\n\n override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) {\n holder.bindItems(backupItemList[position])\n holder.itemView.radioButton.setChecked(position == mSelectedItem);\n }\n\n override fun getItemCount(): Int {\n return backupItemList.size\n }\n\n inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {\n fun bindItems(aMSetting: MSetting) {\n itemView.radioButton.tag=aMSetting._id\n itemView.textViewUsername.text=aMSetting.createdDate.toString()\n itemView.textViewAddress.text=aMSetting.description\n\n …Run Code Online (Sandbox Code Playgroud) 我正在使用此代码将我的视图加载到DialogFragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
SyncPopup syncPopup = new SyncPopup(getActivity(), this,_callback);
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setSoftInputMode(STYLE_NO_INPUT);
getDialog().setCanceledOnTouchOutside(false);
return syncPopup;
}
Run Code Online (Sandbox Code Playgroud)
这段代码在我的自定义DialogFragment中.所以this指向DialogFragment.SyncPopup保存了我的所有视图逻辑.我正在使用这种模式,以便我可以在其他地方重用SyncPopup.
在我的SyncPopup中,我正在运行AsyncTask,onPostExecute我希望关闭DialogFragment.- >
_parentFragment通过构造函数注入,参见上面的代码(使用this指针).
SyncInfo si = new SyncInfo(email, Start, End);
new AsyncTask<SyncInfo, Void, String>() {
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
_callback.onSyncFinish();
_parentFragment.dismiss();
}
@Override
protected String doInBackground(SyncInfo... params) {
SyncInfo si = params[0];
return Cache.sync(si.Email, si.Start, si.End);
}
}.execute(si);
Run Code Online (Sandbox Code Playgroud)
我已经测试了这段代码,但在Google Analytics中,我看到了_parentFragment.dismiss();原因 - >IllegalStateException (@SyncPopup$8:onPostExecute:221) …