这是我的代码我很想尝试在微调显示项目,但都是徒劳的 列表显示时按下微调箭头但没有选择,并做在敬酒不显示,请帮助我,引导我在哪里,我错了微调列表显示时,按微调但列表项不显示,但没有显示在烤面包
public class MakeComplain extends AppCompatActivity implements
OnItemSelectedListener {
private Spinner spinner,spinner1,spinner3;
private TextView txtCategory;
private ArrayList<String> Station;
private JSONArray result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_complain);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
spinner1 = (Spinner) findViewById(R.id.station);
spinner3 = (Spinner) findViewById(R.id.generator);
spinner = (Spinner) findViewById(R.id.complain);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Get data from the list which you had set to the adapter of spinner1
Toast.makeText(MakeComplain.this, "Spinner1 Item Clicked: "+position, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Get data from the list which you had set to the adapter of spinner3
Toast.makeText(MakeComplain.this, "Spinner3 Item Clicked: "+position, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(this, R.array.Complain, android.R.layout.simple_spinner_item);
spinner.setAdapter(arrayAdapter);
spinner1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, this.fetchTwitterPublicTimeline()));
spinner3.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, this.fetchGeneratorList()));
}
public ArrayList<String> fetchTwitterPublicTimeline()
{
final ArrayList<String> listItems = new ArrayList<String>();
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL("http://bigbi.com/cs/Station.php");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
//urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0");
InputStream stream = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
JSONArray ja = new JSONArray(line);
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
listItems.add(jo.getString("name"));
}
}
bufferedReader.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
return listItems;
}
public ArrayList<String> fetchGeneratorList()
{
final ArrayList<String> listItems = new ArrayList<String>();
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL("http://biges.com/12/get.php");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
//urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0");
InputStream stream = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
JSONArray ja = new JSONArray(line);
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
listItems.add(jo.getString("gen_no"));
}
}
bufferedReader.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
return listItems;
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}
后同样的结果没有显示 –