
在我的应用程序中,我应该使用ListVIEw和ArrayAdapter来显示一些列表. (我不应该使用RecyclerVIEw,所以不建议我使用它).
我想在计时器接收到0时删除此项目.
public class AuctionTodaylistadapter extends BaseAdapter { private TextVIEw proname, progresstxt, txtPercent, txtPrice2, txtStartPrice, txtPrice, progressFinishedTxt, text_vIEw_169622, price, timeVIEw, edtUsername, today_inputPriceTxt, today_basePriceTxt, txtDate, under10_priceTxt; private CustomBadge bIDCount, offerCount; private Progressbar progressbar; private ImageVIEw GoodPic, userPic, User; private CountdownVIEw countdownVIEw; public AuctionTodaylistadapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<TodayGmodel> objects) { super(context, resource, objects); } @Suppresslint("SetTextI18n") @NonNull @OverrIDe public VIEw getVIEw(final int position, @Nullable VIEw convertVIEw, @NonNull VIEwGroup parent) { final TodayGmodel model = (TodayGmodel) datas.get(position); VIEw vIEw; if (convertVIEw != null) vIEw = convertVIEw; else vIEw = VIEw.inflate(context, layout, null); Constants.setFont(parent); df = new DecimalFormat(",###.##"); Log.e("todayTimer", model.getCalculateEnd() + ""); proname = (TextVIEw) vIEw.findVIEwByID(R.ID.text_vIEw_16962); progresstxt = (TextVIEw) vIEw.findVIEwByID(R.ID.progresstxt); txtPercent = (TextVIEw) vIEw.findVIEwByID(R.ID.txtPercent); txtPrice2 = (TextVIEw) vIEw.findVIEwByID(R.ID.txtPrice2); txtPrice = (TextVIEw) vIEw.findVIEwByID(R.ID.txtPrice); text_vIEw_169622 = (TextVIEw) vIEw.findVIEwByID(R.ID.text_vIEw_169622); txtStartPrice = (TextVIEw) vIEw.findVIEwByID(R.ID.txtStartPrice); countdownVIEw.setonCountdownIntervalListener(1000, new CountdownVIEw.OnCountdownIntervalListener() { @OverrIDe public voID onInterval(CountdownVIEw cv, long remainTime) { if (remainTime < 10000 && remainTime > 0) { winnerLay.setVisibility(VIEw.GONE); ListItem_winnerLay.setVisibility(VIEw.GONE); ListItem_todayUpper10Lay.setVisibility(VIEw.GONE); ListItem_todayPriceLay.setVisibility(VIEw.VISIBLE); ListItem_under10Lay.setVisibility(VIEw.VISIBLE); under10_priceTxt.setText(df.format(model.getPrice()) + "Dollar"); progressbar.setMax((int) timeInMillis / 1000); isRunning = true; countDownTimer = new CountDownTimer(timeInMillis, 100) { @OverrIDe public voID onTick(long millisUntilFinished) { progresstxt.setText("" + String.valueOf(Math.round(millisUntilFinished * 0.001f))); progressbar.setProgress(Math.round(millisUntilFinished * 0.001f)); } @OverrIDe public voID onFinish() { } }.start(); countDownTimer.start(); } if (remainTime < 0) { startTimer(); remove(position); notifyDataSetChanged(); } } });我写这段代码删除:
if (remainTime < 0) { startTimer(); remove(position); notifyDataSetChanged(); }但对我不起作用,也没有删除任何项目!
如何从适配器中删除物品?
解决方法:
我认为您可以使用此:
if (remainTime < 0) { startTimer(); // your List object datas.remove(position); notifyDataSetChanged(); }嘿,如果不工作,那么我为您创建了一个示例.如果您可以共享xml文件或正确的代码,则它可以正常工作,那么我们可以轻松地为您提供帮助,否则您可以像这样使用.
public class MainActivity extends AppCompatActivity {EditText textVIEw; ArrayList<Integer> newArrayList;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); newArrayList = new ArrayList<>(); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); newArrayList.add(R.mipmap.ic_launcher); GrIDVIEw simpleGrID = (GrIDVIEw) findVIEwByID(R.ID.simpleGrIDVIEw); AuctionTodaylistadapter customAdapter = new AuctionTodaylistadapter(newArrayList); simpleGrID.setAdapter(customAdapter);}public class AuctionTodaylistadapter extends BaseAdapter { Context context; private TextVIEw proname, progresstxt, txtPercent, txtPrice2, txtStartPrice, txtPrice, progressFinishedTxt, text_vIEw_169622, price, timeVIEw, edtUsername, today_inputPriceTxt, today_basePriceTxt, txtDate, under10_priceTxt; ArrayList<Integer> newString; public AuctionTodaylistadapter(ArrayList<Integer> objects) { newString = objects; context = MainActivity.this; } @OverrIDe public int getCount() { return newString.size(); } @OverrIDe public Object getItem(int position) { return null; } @OverrIDe public long getItemID(int position) { return 0; } @OverrIDe public VIEw getVIEw(final int position, @Nullable VIEw convertVIEw, @NonNull VIEwGroup parent) { LayoutInflater inflter = (LayoutInflater.from(getApplicationContext())); VIEw vIEw = inflter.inflate(R.layout.activity_grID, null);//set layout for displaying items ImageVIEw icon = (ImageVIEw) vIEw.findVIEwByID(R.ID.icon); icon.setimageResource(newString.get(position)); icon.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { newString.remove(position); notifyDataSetChanged(); } }); return vIEw; }}} 总结 以上是内存溢出为你收集整理的android-如何从ArrayAdapter中删除项目?全部内容,希望文章能够帮你解决android-如何从ArrayAdapter中删除项目?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)