2014-10-19 91 views
0

我试图找出一种方式来传递多个参数,当用户点击一个字符串使用我的应用程序。我目前只能传递一个字符串,但我必须传递另一个字符串。我通过一个城市(IE实际上是一个城市字符串,波士顿,迈阿密等)。我的目标是通过与城市相关的国家。例如,波士顿也会通过马萨诸塞州,咪咪会通过佛罗里达等...使用onItemClick从数据库传递多个参数android

我的问题是,我将如何通过与该城市相关的状态参数?

我传递从URL来在互联网上的信息

我的URL看起来像这样 http://mywebsite.com/getDealershipCity.php?StateID=florida&CityID=miami

getAllCitiesTextView.setOnItemClickListener(new OnItemClickListener(){ 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 


      String cityClicked = null; 
      try { 
       cityClicked = jsonArray.getString(position); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 

      Log.e("showing position before method = ", cityClicked); 

      APIConnector haveToAccessAMethod = new APIConnector(); 
      String cityClickedAfterMethod = haveToAccessAMethod.returnTheCityString(cityClicked); 

      Log.e("showing position after method = ", cityClickedAfterMethod); 

      Intent show = new Intent(getApplicationContext(), DealerDetailsActivity.class); 
      show.putExtra("cityID", cityClickedAfterMethod); 

      startActivity(show); 


     } 


    }); 

} 
+0

创建一个简单的持有者类,它是可序列化或可分段的,并通过? – cYrixmorten 2014-10-19 01:24:00

回答

0

由于@cYrixmorten建议,你可以创建一个实现Parcelable一个holder类并把它作为一个额外的东西放在你的intent中。你也可以在包含与城市相关的状态的意图中再添加一个额外的内容。如果你选择那个(较短的)解决方案,它看起来像这样:

String stateClickedAfterMethod = ... 

Intent show = new Intent(getApplicationContext(), DealerDetailsActivity.class); 
show.putExtra("cityID", cityClickedAfterMethod); 
show.putExtra("state", stateClickedAfterMethod);