사용자가 서버에서 json 데이터를 가져 와서 목록보기에 넣는 Android 애플리케이션을 개발 중입니다.목록보기에서 (여러) EditText 값을 가져와 배열로 게시하십시오.
목록보기에서 각 항목에는 일부 textViews 및 EditText가 있습니다. 이제 사용자가 EditTexts에 숫자를 입력하고 값을 다시 서버에 보내길 원합니다.
Order.Java :
public class Order extends ListActivity {
UserFunctions userFunctions;
SessionManager session;
TextView text;
private static final String URL = "http://mydomain.in/webservice/json_sas.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_ITEM = "Item";
private static final String TAG_POSTS = "posts";
private static final String TAG_SALE = "sale";
private JSONArray mComments = null;
private ArrayList<HashMap<String, String>> mCommentList;
private JSONArray sasTotal = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
new LoadOrderForm().execute();
}
/**
* Retrieves recent products data from the server.
*/
public void updateJSONdata() {
session = new SessionManager(getApplicationContext());
HashMap<String, String> user = session.getUserDetails();
String cc = user.get(SessionManager.KEY_CC);
mCommentList = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cc", cc));
Log.d("request!", "starting");
JSONParser jParser = new JSONParser();
JSONObject json = jParser.makeHttpRequest(URL, "POST", params);
try {
mComments = json.getJSONArray(TAG_POSTS);
for (int i = 0; i < mComments.length(); i++) {
JSONObject c = mComments.getJSONObject(i);
// gets the content of each tag
String item = c.getString(TAG_ITEM);
String pack = c.getString(TAG_PACK);
String bal = c.getString(TAG_BAL);
String sale = c.getString(TAG_SALE);
String LM1 = c.getString(TAG_LM1);
String LM2 = c.getString(TAG_LM2);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ITEM, item);
map.put(TAG_PACK, pack);
map.put(TAG_BAL, bal);
map.put(TAG_SALE, sale);
map.put(TAG_LM1, LM1);
map.put(TAG_LM2, LM2);
// adding HashList to ArrayList
mCommentList.add(map);
}
sasTotal = json.getJSONArray(TAG_SASARRAY);
// looping through all posts according to the json object returned
for (int i = 0; i < sasTotal.length(); i++) {
JSONObject d = sasTotal.getJSONObject(i);
// gets the content of each tag
String sval = d.getString(TAG_SVAL);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* Inserts the parsed data into the listview.
*/
private void updateList() {
ListAdapter adapter = new SimpleAdapter(this, mCommentList,
R.layout.single_post_order, new String[] { TAG_ITEM,
TAG_SALE,TAG_BAL }, new int[] { R.id.Item, R.id.sale, R.id.stk });
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
public class LoadOrderForm extends AsyncTask<Void, Void, Boolean> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Boolean doInBackground(Void... arg0) {
updateJSONdata();
return null;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
updateList();
}
}
}
}
ListActivity는 다음과 같습니다 : 내가 좋아하는 것
이제https://drive.google.com/file/d/0Bz-FxbI1t7ezMzVoUWo3NXBlWW8/edit?usp=sharing
배울 :
- 을 어떻게 사용자가 입력 한 것을 감지 할 수 있습니다 많은 항목의 EditTexts에있는 숫자입니까?
- Edittext에 입력 된 texview 및 Qty에서 ID 또는 이름을 어떻게 수집합니까?
- 어떻게하면 ARRAY로 서버에 다시 게시 할 수 있습니까?
이미지 .... https를 참조하십시오 그가 클릭하면 편집 텍스트 fileds의 수량 다음 //drive.google.com/file/d/0Bz-FxbI1t7ezMzVoUWo3NXBlWW8/edit USP = 공유 사용자 유형을? 제출 버튼 (사진에는 보이지 않음)은 각 행에서 데이터 (모든 id, editText 값)를 수집하고 배열을 만들어야합니다. –
Okay ... 그런 다음 버튼 객체를 생성자에 보내고 클릭하면보기를 순환합니다. 나는 너에게 답을 편집 할 것이다. 수락하는 것을 잊지 마십시오 – HarshMarshmallow
나는 시도하고 ..... ..... Thx –