В моем проекте есть один activity
с именем ResultActivity.java
и adapter
с именем VoyageAdapter.java
.В ResultActivity
есть одно значение string
, и я хочу отправить это string
на VoyageAdapter.java
.Как это сделать?
ResultActivity.java
public class ResultActivity extends AppCompatActivity {
private String fBus;
}
Я хочу отправить и использовать string
в этой части VoyageAdapter.java
VoyageAdapter.java
public class VoyageAdapter extends RecyclerView.Adapter<VoyageAdapter.ViewHolder> {
@Override
public VoyageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_voyage_view_bus, parent, false);
return new ViewHolder(itemView);
}}
MyBaseVoyageFragment.java
public abstract class MyBaseVoyageFragment extends Fragment {
protected String owner;
protected View fragmentView;
protected String fBus;
protected RecyclerView mRecyclerView;
protected VoyageAdapter voyageAdapter;
protected RecyclerView.LayoutManager mLayoutManager;
protected ArrayList<Voyage> voyageList;
protected View errorView;
public String BROADCAST_TAG = "com.bss.voyage";
protected int direction = MyConstants.DIRECTION_GOING;
ParseIntentDataAndLoadVoyagesAdapter
parseIntentDataAndLoadVoyagesAdapter;
protected void init(String owner, int direction) {
mRecyclerView = fragmentView.findViewById(R.id.my_recycler_view);
mLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
this.owner = owner;
}
void loadVoyagesToAdapter() {
if (voyageAdapter == null) {
voyageAdapter = new VoyageAdapter(getActivity(), voyageList, fBus, mRecyclerView);
fBus="none";
Log.v(fBus, "FRAGMENT BUS");
mRecyclerView.setAdapter(voyageAdapter);
} else {
voyageAdapter.updateList(voyageList); // sonraki güne geçtiğimde yeni bir voyageadapter oluşturmuyorum.
}
if (voyageList.size() < 1 ) {
setErrorView(MyConstants.ERROR_NO_VOYAGE);
}
}
private class ParseIntentDataAndLoadVoyagesAdapter extends AsyncTask<String, Void, String> {
Intent intent;
public ParseIntentDataAndLoadVoyagesAdapter(Intent intent) {
this.intent = intent;
}
@Override
protected String doInBackground(String... params) {
if (isCancelled()) return "";
try {
JSONArray jsonArray = new JSONArray(intent.getStringExtra("data"));
voyageList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
voyageList.add(Voyage.setJsonToClass(jsonArray.getJSONObject(i), direction, owner));
}
} catch (JSONException e) {
Log.e("getIntent", e.toString());
e.printStackTrace();
}
return "";
}
}