Я хочу знать, как передать аргумент пользовательскому адаптеру. Моя ошибкаКак передать аргумент пользовательскому адаптеру?
.Actual argument Fragment cannot be converted to context by method invocation conversion
Error:(51, 27) error: constructor CustomAdapter in class CustomAdapter cannot be applied to given types;
required: Context,List<NodesEntity>
found: FriendsFragment,List<NodesEntity>
reason: actual argument FriendsFragment cannot be converted to Context by method invocation conversion
Мой фрагмент кода
public class FriendsFragment extends Fragment {
ListView video_list;
AsyncHttpClient client;
String url = "*some url*";
Response responseObj;
CustomAdapter adapter;
Gson gson;
private Context globalContext = null;
public FriendsFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
globalContext = this.getActivity().getApplicationContext();
video_list = (ListView) getView().findViewById(R.id.video_list);
client = new AsyncHttpClient();
client.get(FriendsFragment.this, url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, byte[] responseBody) {
String responsestr = new String(responseBody);
gson = new Gson();
responseObj = gson.fromJson(responsestr, Response.class);
adapter = new CustomAdapter(FriendsFragment.this, responseObj.getNodes());
video_list.setAdapter(adapter);
}
@Override
public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, byte[] responseBody, Throwable error) {
//handle error before going to production. maybe use toast or alert.
}
});
video_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View videoView, int position, long id) {
TextView urlTextView = (TextView) videoView.findViewById(R.id.video_url);
String video_url = urlTextView.getText().toString();
Log.d("Info", "onItemClick() returned the url: " + video_url);
onSampleSelected(video_url);
}
});
}
//<Exo Player Invoking Function>
private void onSampleSelected(String video_url) {
Intent mpdIntent = new Intent(this, PlayerActivity.class)
.setData(Uri.parse(video_url))
//.putExtra(PlayerActivity.CONTENT_ID_EXTRA, sample.contentId)
.putExtra(PlayerActivity.CONTENT_TYPE_EXTRA, PlayerActivity.TYPE_HLS);
startActivity(mpdIntent);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_friends, container, false);
// Inflate the layout for this fragment
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
}
//Custom Adapter Code
public class CustomAdapter extends BaseAdapter {
private List<Response.NodesEntity> mMovieitem;
private Context mContext;
private LayoutInflater inflater;
public CustomAdapter(Context mContext, List<Response.NodesEntity> mMovieitem) {
this.mContext = mContext;
this.mMovieitem = mMovieitem;
}
@Override
public int getCount() {
return mMovieitem.size();
}
@Override
public Object getItem(int position) {
return mMovieitem.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.each_list_item, parent, false);
Response.NodesEntity item = (Response.NodesEntity) getItem(position);
ImageView thumbnail = (ImageView) rowView.findViewById(R.id.thumbnail);
TextView title = (TextView) rowView.findViewById(R.id.title);
TextView rating = (TextView) rowView.findViewById(R.id.video_url);
String imageUrl = item.getVideoTumbnail().getSrc();
Picasso.with(mContext).load(imageUrl).into(thumbnail);
title.setText(item.getTitle());
rating.setText(item.getHlsVideo());
return rowView;
}
}
Ошибка: (42, 15) Ошибка: не подходящий метод нашел для ГЭТ (FriendsFragment, String, <анонимным AsyncHttpResponseHandler>) метод AsyncHttpClient.get (Context, String, HttpEntity, String, ResponseHandlerInterface) не применяется (фактическая и формальные списки аргументов различаются по длине) метод AsyncHttpClient.get (Контекст, String, Header [], RequestParams, ResponseHandlerInterface) не применим (списки фактических и формальных аргументов различаются по длине) – BinoyBinzzzz