私はスピナーを1つ持っていて、それを投入しています。値のリストがあり、スピナーが選択した位置も取得しています。ここで、スピナーアイテムの選択位置に基づいて値のリストを表示したいと思います。どうやってするか。誰か助けてくれませんか?
2 に答える
2
問題はデータの構造化だと思います
以下のような構造データ
1- Bean / Modelを使用して、jsonから取得する単位としてすべてのデータをラップします
if (loadseq == index) {
Dealer dealer = new Dealer();
dealer.setVIN(js.getString("vin");)
.......
.....
al.add(dealer);
public class Dealer{
private String dealer_name1 ;
private Vehicle ;
private String vin ;
private String color ;
private String parking ;
private String vindesc ;
//getter seeter of all
@Override
public String toString() {
return dealer_name1;
}
}
class mySpinnerListener implements Spinner.OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
Dealer d = (Dealer) parent.getItemAtPosition(position);
or
Dealer d = al.elmentAt(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
于 2012-06-27T07:33:05.627 に答える
2
ねえ、これは私のために働いています...最初のことは...これを国のスピナーと言います
/ * ** * ** * ** * ****国のスピナー**** ** * ** * *** / _ _
ArrayList<NameValuePair> alcountry = new ArrayList<NameValuePair>();
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://blah.com/country.php");
httppost.setEntity(new UrlEncodedFormEntity(alcountry));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
Countryresult=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
try{
countryarray = new JSONArray(Countryresult);
JSONObject json_data=null;
for(int i=0;i<countryarray.length();i++){
json_data = countryarray.getJSONObject(i);
Countrylist.add(json_data.getString("country_name"));
System.out.println("hq value is " +Countrylist);
Countryadapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Countrylist);
country.setAdapter(Countryadapter);
country.setOnItemSelectedListener(this);
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
/*****************************end of spinner for country*******************/
次に、オーバーライドされたメソッドで
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
// TODO Auto-generated method stub
state = (Spinner)findViewById(R.id.etstate);
Statelist = new ArrayList<String>();
/*****************************spinner for state based on country**************************/
ArrayList<NameValuePair> alstate = new ArrayList<NameValuePair>();
alstate.add(new BasicNameValuePair("country_name",country.getSelectedItem().toString()));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://blah.com/state.php");
httppost.setEntity(new UrlEncodedFormEntity(alstate));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
Stateresult=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
try{
statearray = new JSONArray(Stateresult);
JSONObject json_data=null;
for(int i=0;i<statearray.length();i++){
json_data = statearray.getJSONObject(i);
Statelist.add(json_data.getString("state_name"));
System.out.println("hq value is " +Statelist);
Stateadapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Statelist);
state.setAdapter(Stateadapter);
}
}
catch(JSONException e1){
Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
state.setOnItemSelectedListener(this);
/*****************************end of spinner for state*******************/
}
だからこれはあなたがそれをする方法です...
于 2012-06-27T07:47:28.233 に答える