[英]How to add values from ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>> to Edit Text
我想添加我的值來編輯我存儲在我的數據列表中的文本,這里的代碼請幫幫我。 編輯文本中未設置的值。
public class AgentProfile extends Activity {
EditText edtname,edtaddress,edtmobile,edtfather;
Button bback;
private SimpleAdapter adapter;
static final String KEY_TABLE = "AGENTPROFILE";
static final String KEY_NAME = "AGENTNAME";// parent node
static final String KEY_ADDRESS = "ADDRESS";// parent node
static final String KEY_COUNTRY= "COUNTRY";
static final String KEY_MOBILE = "MOBNO1";
static final String KEY_FATHER= "FATHERNAME";
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agent_profile);
edtname= (EditText) findViewById(R.id.edtname);
edtaddress= (EditText) findViewById(R.id.edtaddress);
edtmobile= (EditText) findViewById(R.id.edtmobile);
edtfather= (EditText) findViewById(R.id.edtfather);
bback= (Button) findViewById(R.id.btnback);
select s=new select();
s.execute("");
bback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(AgentProfile.this, MainActivity.class);
startActivity(i);
}
});
}
public class select extends AsyncTask<String,Void, String> {
HashMap<String, String> map = new HashMap<String, String>();
@Override
protected String doInBackground(String... strings) {
WebServiceCall com = new WebServiceCall();
Intent intent =getIntent();
Bundle b =intent.getExtras();
final String string1 = getIntent().getStringExtra("Agentid");
// messageBox("test", Agentid);
String strXml=com.BP("AgentProfile",string1);
//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
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
map.put(KEY_ADDRESS, parser.getValue(e, KEY_ADDRESS));
map.put(KEY_COUNTRY, parser.getValue(e, KEY_COUNTRY));
map.put(KEY_MOBILE, parser.getValue(e,KEY_MOBILE));
map.put(KEY_FATHER, parser.getValue(e, KEY_FATHER));
// adding HashList to ArrayList
menuItems.add(map);
}
return strXml;
}
@Override
protected void onPostExecute(String s) {
edtmobile.setText(KEY_MOBILE);
edtfather.setText(KEY_FATHER);
}
}
private boolean connectionAvailable() {
boolean connected = false;
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED ||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_SUPL).getState() == NetworkInfo.State.CONNECTED) {
//we are connected to a network
connected = true;
}
return connected;
}}
這里是代碼,請幫我在編輯文本中存儲值。
edtmobile.setText(map.get(KEY_MOBILE));
edtfather.setText(map.get(KEY_FATHER));
如果要將網絡調用的結果發布回UI,請使用onPostExecute()方法,因為它在UI線程上運行。
@Override
protected void onPostExecute(String s) {
//Get the results of the network call
map = menuItems.get(0);
edtname.setText(map.getValue(KEY_NAME));
edtaddress.setText(map.getValue(KEY_ADDRESS));
edtmobile.setText(map.getValue(KEY_MOBILE));
edtfather.setText(map.getValue(KEY_FATHER));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.