我得到的警告對話框微調JSON響應微調值,現在我想用逗號的EditText分隔用戶選擇的項目,但是當我運行的應用程序,我能夠只選擇一個,並在我的EditText它顯示只有一個項目......如何讓TextView的
public class MainActivity extends Activity {
JSONParser jsonParser = new JSONParser();
JSONArray country_list=null;
private static String BUSINESS_URL = "";
private static final String BUSINESS_ID="id";
private static final String BUSINESS_NAME="name";
ArrayList<HashMap<String,String>> data;
private TextView splang;
private String cname;
private String business_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
splang=(TextView)findViewById(R.id.txtvw);
new LoadBusiness().execute();
}
class LoadBusiness extends AsyncTask<String, String, ArrayList<HashMap<String,String>>> {
ArrayAdapter<String> adaptercountry ;
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
// pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress));
pDialog.setCancelable(true);
pDialog.show();
}
protected ArrayList<HashMap<String,String>> doInBackground(String... args) {
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
data = new ArrayList<HashMap<String, String>>();
String jsonStr = sh.makeServiceCall(BUSINESS_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
country_list = new JSONArray(jsonStr);
// looping through All Contacts
for (int i = 0; i < country_list.length(); i++) {
JSONObject c = country_list.getJSONObject(i);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(BUSINESS_ID, c.getString(BUSINESS_ID));
map.put(BUSINESS_NAME,c.getString(BUSINESS_NAME));
data.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return data;
}
protected void onPostExecute(ArrayList<HashMap<String,String>> result) {
super.onPostExecute(result);
pDialog.dismiss();
String[] arrConuntry=new String[data.size()];
for(int index=0;index<data.size();index++){
HashMap<String, String> map=data.get(index);
arrConuntry[index]=map.get(BUSINESS_NAME);
}
// pass arrConuntry array to ArrayAdapter<String> constroctor :
adaptercountry = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_multiple_choice,
arrConuntry);
splang.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View w) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Select")
.setAdapter(adaptercountry, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
splang.setText(adaptercountry.getItem(which).toString());
try {
cname=country_list.getJSONObject(which).getString("id");
Log.d("Response: ", "> " + cname);
business_id=cname.toString();
System.out.println("Business_id"+business_id);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dialog.dismiss();
}
}).create().show();
}
});
}
}
問題是不能選擇多個項目,並將其存儲在TextView中 – malis 2015-04-07 09:25:19
你念的問題? – malis 2015-04-07 11:13:36
採取從參考下面給出的鏈接http://v4all123.blogspot.in/2013/09/spinner-with-multiple-selection-in.html – 2015-04-08 13:59:22