如何在DialogFragment中的TextView中创建计数器?

时间:2016-06-15 11:33:53

标签: android counter textview

我在制作包含计数器的DialogFragment时遇到问题(例如计算传入文件的数量,例如0/50 50/50)。问题是更新TextView以显示即将到来的文件数。 你能帮我解决这个问题吗? 谢谢!

public class ProgressDialogFragment extends DialogFragment {

    public static ProgressDialogFragment newInstance(String title) {
    ProgressDialogFragment frag = new ProgressDialogFragment();
    Bundle args = new Bundle();
    args.putString("title", title);
    frag.setArguments(args);
    return frag;
}

private View view;
private String title;
public TextView textViewLoading;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    view = inflater.inflate(R.layout.loading_dialog_layout, container);

    textViewLoading = (TextView)view.findViewById(R.id.text_view_loading);

    return view;
}

public void updateCount(int position, int size) {
    textViewLoading.setText(title + " " + position + "/" + size);
}`

然后实例化这个类:

ProgressDialogFragment dialogProgressLoading = ProgressDialogFragment.newInstance("load challenges"); dialogProgressLoading.show(manager, "tag");

并尝试更新计数:

   `dialogProgressLoading.updateCount(position, values.size());`

它不起作用。我尝试从适配器更新计数器

1 个答案:

答案 0 :(得分:0)

 private int count = 0;
 private TextView fileCounterText;



 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

 fileCounterText = (TextView) findViewbyId(R.id.textviewsXMLid);

for(int i = 0; i < 50; i++)
 {
    //file code
    count++;
    fileCounterText.setText("count");
  }