Я сделал второй фрагмент, в котором я получил значение от 1-го фрагмента. Но проблема в том, что я не могу установить полученное текстовое представление второго фрагмента.Как установить значение в держателе данных фрагмента?
Я использую Log.d()
; метод, чтобы проверить, но я обнаружил, что databindholder никогда не называют:
Выпуск 1: databindholder не называется
Выпуск 2: не может установить значение в TextView 2-го фрагмента
Благодарим вас за беспокойство!
public class ListTable extends Fragment {
private RecyclerView recyclerView;
public ListTable() {
// Required empty public constructor
}
public static ListTable newInstance(String param1, String param2) {
ListTable fragment = new ListTable();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_list_table, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
MyAdapter a = new MyAdapter();
// a.notifyDataSetChanged();
recyclerView.setAdapter(a);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
public void receiveValue(String value) {
int result = Integer.parseInt(value);
Bundle bundle = new Bundle();
bundle.putInt("value", result);
ListTable listTable = new ListTable();
listTable.setArguments(bundle);
MyAdapter b=new MyAdapter();
b.notifyDataSetChanged();
// a.notifiedatachanged
Log.d("ashu", "value recived :" + value);
}
public class MyAdapter extends RecyclerView.Adapter<MyDataViewHolder> {
@Override
public MyDataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.fragment_list_table, parent, false);
return new MyDataViewHolder(view);
}
@Override
public void onBindViewHolder(MyDataViewHolder holder, int position) {
if (getArguments() != null) {
int value1 = getArguments().getInt("value");
Log.d("ashu", "the value received inthe bindholder is " + value1);
holder.myEditText.setText("Table is: " + position * value1);
}
}
@Override
public int getItemCount() {
return 10;
}
}
public class MyDataViewHolder extends RecyclerView.ViewHolder {
public TextView myEditText;
public MyDataViewHolder(View itemView) {
super(itemView);
myEditText = (TextView) itemView.findViewById(R.id.table_value);
}
}
}