我创建了一个应用程序,我从服务器获取数据并在列表视图中使用微调器显示数据,但我的列表视图显示为空我想显示数据,如bleow image
我的基础适配器是
public class Test_adapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Audio_Model> movieItems;
private List<Audio_Model> adapterInitialMovieList = null;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public Test_adapter(Activity activity, List<Audio_Model> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
}
public void setDataOnSpinnerSelected(List<Audio_Model> audioList){
adapterInitialMovieList = audioList;
notifyDataSetChanged();
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int location) {
return movieItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (inflater == null) {
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.test_row, null);
viewHolder = new ViewHolder();
viewHolder.play = (ImageButton) convertView.findViewById(R.id.audioplay);
viewHolder.stop = (ImageButton) convertView.findViewById(R.id.audiostop);
viewHolder.seekBar = (SeekBar) convertView.findViewById(R.id.seekbar_audio1);
viewHolder.share = (ImageButton) convertView.findViewById(R.id.audioshare1);
}else{
viewHolder =(ViewHolder)convertView.getTag();
}
viewHolder.play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
viewHolder.stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
viewHolder.share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
viewHolder.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
return convertView;
}
public class ViewHolder {
SeekBar seekBar;
ImageButton play,stop,share;
}
}
和活动
private Spinner mSpinner;
ArrayList<String> students;
private JSONArray result;
private static final String TAG = MainActivity.class.getSimpleName();
private static final String url = "http://www.example.com/json_audio.php";
private ProgressDialog pDialog;
private List<Audio_Model> audioList = new ArrayList<Audio_Model>();
private ListView audio_List;
private Audio_Adapter adapter;
Json_Data j_Data = new Json_Data();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_activity);
students = new ArrayList<String>();
audio_List = (ListView) findViewById(R.id.audio_list);
mSpinner =(Spinner)findViewById(R.id.audioSpinner);
listdata();
getData();
adapter = new Audio_Adapter(this, audioList);
audio_List.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(this);
students.add("Get Category");
audio_List.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String link= audioList.get(position).getAudiolink();
Intent audointent = new Intent(getApplicationContext(),Audio_PlayActivity.class);
audointent.putExtra("link",link);
startActivity(audointent);
finish();
Log.e("hello audio","link==>"+link);
}
});
pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
}
public void listdata(){
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Audio_Model _audio = new Audio_Model();
Test_model test_model= new Test_model();
_audio.setAudioname(obj.getString("txt"));
_audio.setThumbnailUrl(obj.getString("audio_img"));
_audio.setAudiolink(obj.getString("audio"));
audioList.add(_audio);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(movieReq);
}
private void getData() {
StringRequest stringRequest = new StringRequest(Config.DATA_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject j_obj = null;
try {
j_obj = new JSONObject(response);
result = j_obj.getJSONArray(Config.JSON_ARRAY);
//Calling method getStudents to get the students from the JSON Array
getStudents(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void getStudents(JSONArray j) {
for (int i = 0; i < j.length(); i++) {
try {
JSONObject json = j.getJSONObject(i);
students.add(json.getString(Config.TAG_USERNAME));
} catch (JSONException e) {
e.printStackTrace();
}
}
//Setting adapter to show the items in the spinner
mSpinner.setAdapter(new ArrayAdapter<String>(Audio_Activity.this, android.R.layout.simple_spinner_dropdown_item, students));
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
String text_spinner1 = mSpinner.getSelectedItem().toString();
j_Data.setSpintext(text_spinner1);
makeJsonArrayRequest();
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
}
@Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
但列表视图显示为空白
帮助我在哪里做错了