我陷入困境,因为我不知道如何更改填充listView
以填充微调器。
当布局微调器更改为listview
时,下面的代码应该有效,但我需要微调器。
任何人都可以向我解释如何做到这一点吗?
在Java文件中,我使用DefaultHttpClient
方法。
MainActivity:
public class MainActivity extends ActionBarActivity {
private Spinner spinner;
private JSONArray jsonArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.spinner=(Spinner) this.findViewById(R.id.spinner);
new GetStat().execute(new Polaczenie());
}
public void setSpinner(JSONArray jsonArray){
this.spinner.setAdapter(new GetAllTeamListViewAdapter(jsonArray,this));
//this.GetStat.setAdapter(new GetAllTeamListViewAdapter(jsonArray,this));
}
public class GetStat extends AsyncTask<Polaczenie,Long,JSONArray>
{
@Override
protected JSONArray doInBackground(Polaczenie... params)
{
return params[0].GetStat();
}
@Override
public void onPostExecute(JSONArray jsonArray)
{
setSpinner(jsonArray);
}
}
}
GetAllTeamListViewAdapter活动:
public class GetAllTeamListViewAdapter扩展了BaseAdapter {
private JSONArray dataArray;
private Activity activity;
private static LayoutInflater inflater = null;
public GetAllTeamListViewAdapter(JSONArray jsonArray, Activity a)
{
this.dataArray=jsonArray;
this.activity=a;
inflater=(LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return this.dataArray.length();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ListTeam team;
if(convertView == null)
{
convertView= inflater.inflate(R.layout.get_all_team_list_view, null);
team = new ListTeam();
team.Name=(TextView) convertView.findViewById(R.id.team_full_name);
}
else
{
team =(ListTeam) convertView.getTag();
}
try
{
JSONObject jsonObject=this.dataArray.getJSONObject(position);
team.Name.setText(jsonObject.getString("name"));
}
catch(JSONException e)
{
e.printStackTrace();
}
return convertView;
}
private class ListTeam
{
private TextView Name;
}
}