如果在理解如何解析数据时遇到问题,我有一个recycleview,它是从company数组中获取其文本集的,当用户单击某个卡时,该卡的companynumber应该附加到另一个我无法查询的URL上弄清楚怎么做谢谢您的帮助
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int i) {
//companyList= new ArrayList<Company>();
Company company = companies.get(i);
viewHolder.textViewHead.setText(company.getCompanyTitle());
viewHolder.textviewDesc.setText(company.getCompanyType());
viewHolder.textViewNumber.setText(company.getCompanyNumber());
viewHolder.linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
///send these to nodes them attach the officers, get both in nodes and send to myview
Company company1 = companies.get(i);
Intent skipintent = new Intent(view.getContext(), Nodes.class);
skipintent.putExtra(KEY_NAME, company1.getCompanyTitle());
skipintent.putExtra(KEY_TYPE, company1.getCompanyType());
skipintent.putExtra(KEY_NUMBER, company1.getCompanyNumber());
// view.getContext().startActivity(skipintent);
Bundle bundle = new Bundle();
bundle.putString(KEY_NAME, company1.getCompanyTitle());
bundle.putString(KEY_TYPE, company1.getCompanyType());
bundle.putString(KEY_NUMBER, company1.getCompanyNumber());
skipintent.putExtras(bundle);
new RetrieveFeedTask(//dont know what to put here).execute();
}
});
}
@Override
public int getItemCount() {
return companies.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView textViewHead;
private TextView textviewDesc;
private TextView textViewNumber;
private LinearLayout linearLayout;
public ViewHolder(@NonNull View itemView) {
super(itemView);
textViewHead = (TextView) itemView.findViewById(R.id.textviewhead);
textviewDesc = (TextView) itemView.findViewById(R.id.textviewDesc);
textViewNumber = (TextView) itemView.findViewById(R.id.textviewNumber);
linearLayout = (LinearLayout) itemView.findViewById(R.id.linearLayout);
}
}
class RetrieveFeedTask extends AsyncTask<String, Void, String> {
private Exception exception;
protected String doInBackground(String... strings) {
///here i want to put the texviewnumber
try {
URL url = new URL(API_URL + textviewnumber +"/officers");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
答案 0 :(得分:0)
我认为您在创建网址时遇到问题。
首先,不要插入空格。
并且您没有得到textviewnumber文本。
尝试
URL url = new URL(API_URL + textviewnumber.getText() +"/officers");
我希望你完成工作。
答案 1 :(得分:0)
您可以像这样将参数传递给asyncTask:
new RetrieveFeedTask().execute(myStringArrayParameter);
,您可以在asyncTask中访问以下内容:
URL url = new URL(API_URL + strings[0] +"/officers");
您的doInBackground()方法如下所示:
doInBackground(String... strings)
这意味着您可以添加String数组作为参数。