1
データフォームWebサービスをスピナーに表示したいが、データはスピナーに表示されないので、これは私のコードです。soapメソッドを使用してスピナーの値を表示
メインアクティビティコード:
public class AgentProgress extends Activity {
Spinner sp1,sp2;
ListView ls1;
ProgressBar pbbar;
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
static final String KEY_TABLE = "AGENTDATA";
static final String KEY_AGENT_NAME = "Parent_Agent_Name";// parent node
static final String KEY_BRANCH_NAME = "Branch_Name";// parent node
static final String KEY_UW_YEAR = "Uw_Year";
static final String KEY_CONTRIBUTION = "Contribution";
static final String KEY_ADJ = "Adj";
static final String KEY_TARGET = "Target";
static final String KEY_DEF = "DEF";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agent_progress);
sp1= (Spinner) findViewById(R.id.spnames);
sp2= (Spinner) findViewById(R.id.spyear);
ls1= (ListView) findViewById(R.id.lstproducts);
pbbar= (ProgressBar) findViewById(R.id.pbbar);
FillList f=new FillList();
f.execute("");
pbbar.setVisibility(View.GONE);
}
public class FillList extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... strings) {
WebServiceCAll com = new WebServiceCAll();
final String string1 = getIntent().getStringExtra("Agentid");
String strXml = com.LoadAgent("LoadAgent");
try {
//messageBox("test", strXml);
XMLParser parser = new XMLParser();
Document doc = parser.getDomElement(strXml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_TABLE);
//String[] arList = null;
//String[] arListkey = null;
// int conttotal=0;
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_AGENT_NAME, parser.getValue(e, KEY_AGENT_NAME));
//map.put(KEY_BRANCH_NAME, parser.getValue(e, KEY_BRANCH_NAME));
//map.put(KEY_UW_YEAR, parser.getValue(e, KEY_UW_YEAR));
//map.put(KEY_CONTRIBUTION, parser.getValue(e, KEY_CONTRIBUTION));
// adding HashList to ArrayList
menuItems.add(map);
//messageBox("test", "fahad");
}
} catch (Exception ex) {
Log.e("Error", "", ex);
}
return strXml;
}
@Override
protected void onPostExecute(String s) {
try {
SimpleAdapter mSchedule = new SimpleAdapter(AgentProgress.this, menuItems, R.layout.activity_agent_progress,
new String[]{"Parent_Agent_Name"},new int[]{R.id.spnames});
mSchedule.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp1.setAdapter(mSchedule);
} catch (Exception exception) {
//Toast.makeText(Login.this,exception.toString(),Toast.LENGTH_SHORT).show();
Log.e("Error", "", exception);
}
}
}
}
ソープクラスコード:
public String LoadAgent(String MethodName)
{
try {
SOAP_ACTION = namespace + MethodName;
//Adding values to request object
request = new SoapObject(namespace, MethodName);
//Adding String value to request object
SetEnvelope();
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
String result = envelope.getResponse().toString();
return result;
}
catch (Exception e)
{
// TODO: handle exception
return e.toString();
}
}
catch (Exception e)
{
// TODO: handle exception
return e.toString();
}
}
私を助けてください。これはコードで教えてください。