我在RecyclerView甚至是Android上都是全新的
我能做到但只定义索引的值而不是在列表中显示文本结果可能是我做错了
这是我的代码
public class CatListFragment extends Fragment {
private RecyclerView recyclerView;
private AdapterForCateg adapter;
public static final String MESSAGE = "one";
private String changeString;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.list_view_frag,container,false);
recyclerView = (RecyclerView) view.findViewById(R.id.categ_list);
adapter = new AdapterForCateg(getActivity(),getData());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(),recyclerView, new ClickListener() {
@Override
public void onClick(View v, int position) {
changeString = String.valueOf(position);
Intent intent = new Intent();
intent.putExtra(MESSAGE,changeString);
getActivity().setResult(11,intent);
getActivity().finish();
}
....
这是我接收数据的其他活动
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 11){
String mak = data.getStringExtra(MESSAGE);
textView.setText(mak);
}
}