Данные все получаю но у меня почему то они не отображаются
public class MainActivity extends AppCompatActivity {
private VideotapeRecordingsAdapter mAdapter;
private List<VideotapeRecordings> mVideotapeRecordings = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lvVideotapeRecordings = findViewById(R.id.listViewVideotapes);
mAdapter = new VideotapeRecordingsAdapter(MainActivity.this, mVideotapeRecordings);
lvVideotapeRecordings.setAdapter(mAdapter);
new GetVideotapeRecordings().execute();
}
private class GetVideotapeRecordings extends AsyncTask<Void, Void, String>
{
@Override
protected String doInBackground(Void... voids) {
try
{
URL url = new URL("http://10.0.2.2:63599/api/VideotapesRecordings");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder result = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null)
{
result.append(line);
}
return result.toString();
} catch (Exception ex) {
return null;
}
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
JSONArray tempArray = new JSONArray(s);
for (int i = 0; i < tempArray.length(); i++)
{
JSONObject recordingJson = tempArray.getJSONObject(i);
VideotapeRecordings tempVideotapeRecording = new VideotapeRecordings(
recordingJson.getInt("id"),
recordingJson.getString("name"),
recordingJson.getString("category"),
recordingJson.getInt("year"),
recordingJson.getString("manufacturer"),
recordingJson.getInt("price"),
recordingJson.getString("image")
);
mVideotapeRecordings.add(tempVideotapeRecording);
mAdapter.notifyDataSetChanged();
}
} catch (Exception ex) {
}
}
}
}
Адаптер
public class VideotapeRecordingsAdapter extends BaseAdapter {
private Context mContext;
private List<VideotapeRecordings> mVideotapeRecordingsList;
public VideotapeRecordingsAdapter(Context mContext, List<VideotapeRecordings> mVideotapeRecordingsList) {
this.mContext = mContext;
this.mVideotapeRecordingsList = mVideotapeRecordingsList;
}
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v = View.inflate(mContext, R.layout.item_videotape, null);
ImageView imgSource = v.findViewById(R.id.imageViewItemVideotapeRecording);
TextView textName = v.findViewById(R.id.textViewItemVideotapeRecordingName);
TextView textYear = v.findViewById(R.id.textViewItemVideotapeRecordingYear);
VideotapeRecordings currentVideotapeRecording = mVideotapeRecordingsList.get(i);
imgSource.setImageBitmap(currentVideotapeRecording.getBitmapSource());
textName.setText(currentVideotapeRecording.getName());
textYear.setText(currentVideotapeRecording.getYear());
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intentDetails = new Intent(mContext, DetailsActivity.class);
intentDetails.putExtra("videotapeRecording", currentVideotapeRecording);
mContext.startActivity(intentDetails);
}
});
return v;
}
}