2014-04-28 4 views
0

사용자가 서버에서 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

배울 :

  1. 을 어떻게 사용자가 입력 한 것을 감지 할 수 있습니다 많은 항목의 EditTexts에있는 숫자입니까?
  2. Edittext에 입력 된 texview 및 Qty에서 ID 또는 이름을 어떻게 수집합니까?
  3. 어떻게하면 ARRAY로 서버에 다시 게시 할 수 있습니까?

답변

0

사실 저는 이전 프로젝트에서이 작업을 수행했습니다. 희망을 갖고 나는 당신에게 당신의 질문에 대한 통찰력있는 답변을 줄 수 있기를 바랍니다.

1) 고유 한 어댑터 클래스를 만들고 그렇게 확장해야합니다.

2) 편집보기를 확장하여 목록에있는 텍스트 뷰의 ID를 확인합니다. 이 뷰가있는 버튼이 있다고 가정합니다.

3) init 함수에 서버 객체를 전달하고 버튼을 클릭했을 때 메소드를 참조하십시오.

public class MyAdapter extends SimpleAdapter{ 

... 
    private final ServerClass server; 
    private Button submit; 

public MyAdapter(Context context, 
     List<? extends HashMap<String, ?>> data, int resource, String[] from, int[] to, ServerClass server, Button submit) { 
    super(context, data, resource, from, to); 

      this.server = server; 
      this.submit = submit; 
      /*set up all of your init stuff here so you can figure out which view was changed when getview is called*/ 

} 

public View getView(int position, View v, ViewGroup parent) 
{ 
    final View mView = super.getView(position, v, parent); 

     submit.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      for(int i = 0; i < parent.getChildCount(); i++){ 
       View row = parent.getChildAt(i); 
       View textview= row.findViewById(/*textviewID*/); 
       View editview= row.findViewById(/*editviewID*/); 
       Log.i("CustomText!!!",textview.getText()); 
       Log.i("CustomText!!!",editview.getText()); 
       server.sendPOSTMethod(textview.getText(),editview.getText()); 
      } 
     } 
    }); 

    return mView; 
} 
+0

이미지 .... https를 참조하십시오 그가 클릭하면 편집 텍스트 fileds의 수량 다음 //drive.google.com/file/d/0Bz-FxbI1t7ezMzVoUWo3NXBlWW8/edit USP = 공유 사용자 유형을? 제출 버튼 (사진에는 보이지 않음)은 각 행에서 데이터 (모든 id, editText 값)를 수집하고 배열을 만들어야합니다. –

+0

Okay ... 그런 다음 버튼 객체를 생성자에 보내고 클릭하면보기를 순환합니다. 나는 너에게 답을 편집 할 것이다. 수락하는 것을 잊지 마십시오 – HarshMarshmallow

+0

나는 시도하고 ..... ..... Thx –

관련 문제