2016-05-27 6 views
0

ダイナミックアイテムとリストビューを使用しています。間違った場所に保存しています(3番目のアイテムに1番目のアイテムが表示され、5番目のアイテムに2番目のアイテムが表示されます)。関連コードを追加しました。確認してください。リストビュー項目が間違った場所に追加されました

EDIT:私は右を表示する必要がバレーボールの応答順序に基づいて

 ArrayList<UpcomingGoalItems> itemsaArrayList; 
     UpcomingGoalAdapter itemsAdapter; 
     ListView listView; 

     itemsaArrayList = new ArrayList<UpcomingGoalItems>(); 
      itemsAdapter = new UpcomingGoalAdapter(UpcomingGoalActivity.this, R.layout.adapt_upcoming_goal, itemsaArrayList); 

      listView = (ListView) findViewById(R.id.lv_interest_goal_search); 

     listView.setAdapter(itemsAdapter); 

     hitGoalApi(); 


    private void hitGoalApi(){ 


     String myGoalsUrl = PK_MY_GOALS; 
     Log.e("myGoalsUrl", myGoalsUrl); 

     StringRequest request = new StringRequest(Request.Method.GET, myGoalsUrl, new Response.Listener<String>() { 

      @Override 
      public void onResponse(String response) { 

       dialog.dismiss(); 

       if(response != null && !response.startsWith("<HTML>")){ 

        Log.e("MyGoalsRes", response); 

        try { 

         JSONObject jsonObject = new JSONObject(response); 

         JSONArray jsonArrData = jsonObject.getJSONArray("data"); 

         for(int i=0; i < jsonArrData.length(); i++){ 

          JSONObject getDataJsonObj = jsonArrData.getJSONObject(i); 

          LOCATION = getDataJsonObj.getString("location"); 

          String[] placeArray = LOCATION.split("\\s*,\\s*"); 

          Log.e("placeArray", ""+ Arrays.toString(placeArray)); 

          String placeStr = placeArray[0]; 

          FROM_DATE = getDataJsonObj.getString("fromdate"); 

          TO_DATE = getDataJsonObj.getString("todate"); 

          GOAL_ID = getDataJsonObj.getString("g_id"); 

          getInterest = getDataJsonObj.getString("users_interest_goals"); 

          hitCountApi(GOAL_ID, placeStr, FROM_DATE, TO_DATE, getInterest); 



         } 

        } 

        catch (JSONException e){ 

         e.printStackTrace(); 
        } 

       }else{ 

        toastShort(getApplicationContext(), "Check Internet"); 
       } 

      } 
     } 


    private void hitCountApi(final String goalId, final String splitLoc, final String fromDate, 
          final String toDate, final String getInteresn) { 


     String countUrl = PK_GOAL_SEARCH + goalId + ".json"; 
     Log.e("countUrl", countUrl); 

     StringRequest request = new StringRequest(Request.Method.GET, countUrl, new Response.Listener<String>() { 

      @Override 
      public void onResponse(String response) { 

       dialog.dismiss(); 

       if (response != null && !response.startsWith("<HTML>")) { 

        Log.e("CountRes", response); 

        try { 

         JSONObject jsonObject = new JSONObject(response); 

         JSONObject metaJsonObj = jsonObject.getJSONObject("_metadata"); 

         String totalRecStr = metaJsonObj.getString("total_records"); 

         Log.e("totalRecStr", "" + totalRecStr); 

         UpcomingGoalItems items = new UpcomingGoalItems(); 

         items.setSplitLocation(splitLoc); 
         items.setFromDate(fromDate); 
         items.setToDate(toDate); 
         items.setGoalId(goalId); 
         items.setInterest(getInterest); 
         items.setCount(totalRecStr);     ; 

         itemsaArrayList.add(items); 
         itemsAdapter.notifyDataSetChanged(); 


        } catch (JSONException e) { 

         e.printStackTrace(); 
        } 

       } else { 

        toastShort(getApplicationContext(), "Check Internet"); 
       } 

      } 
     }) 

UpcomingGoalAdapter.java:

public class UpcomingGoalAdapter extends ArrayAdapter<UpcomingGoalItems> { 
    private Context context; 
    @SuppressWarnings("unused") 
    private List<UpcomingGoalItems> items; 
    String eventIdForVol; 
    private UpcomingGoalAdapter adapter; 
    String userIdStr, tokenStr; 

    public UpcomingGoalAdapter(Context context, int resource, List<UpcomingGoalItems> objects) { 
     super(context, resource, objects); 
     this.context = context; 
     this.items = objects; 
     this.adapter = this; 
    } 

    @SuppressLint("InflateParams") 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder = null; 

     final UpcomingGoalItems rowItem = getItem(position); 

     LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.adapt_upcoming_goal, null); 
      holder = new ViewHolder(); 

      holder.tvInterest = (TextView) convertView.findViewById(R.id.tv_interest_goal_adapt); 
      holder.ivEdit = (ImageView) convertView.findViewById(R.id.iv_edit_goal_adapt); 
      holder.tvCount = (TextView) convertView.findViewById(R.id.tv_count_goal_adapt); 
      holder.ivDelete = (ImageView) convertView.findViewById(R.id.iv_delete_goal_adapt); 


      convertView.setTag(holder); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 
     } 



     if((rowItem.getInterest().equals(null) || rowItem.getInterest().equals("")) 
       && (rowItem.getLocation().equals(null) || rowItem.getLocation().equals("")) 
       && (rowItem.getFromDate().equals(null) || rowItem.getFromDate().equals("")) 
       && (rowItem.getToDate().equals(null) || rowItem.getToDate().equals(""))) { 

      holder.tvInterest.setText("-"); 

     } else { 

      holder.tvInterest.setText("Looking for "+rowItem.getInterest() + " in " + rowItem.getSplitLocation() + " On (" 
        + rowItem.getFromDate() + " - " + rowItem.getToDate()+") "); 
     } 


     holder.tvCount.setText(rowItem.getCount()); 

     return convertView; 
    } 

    private class ViewHolder { 
     TextView tvInterest; 
     ImageView ivEdit; 
     TextView tvCount; 
     ImageView ivDelete; 
    } 

UpcomingGoalActivity.javaリストビューのidです.It ta kesの間違った順序。

なぜそれが間違った場所で注文しているのか、これを解決する方法を教えてください。ありがとう。

答えて

0

tldr:リストの代わりに使用ArrayListの:

private ArrayList<UpcomingGoalItems> items; 

私が使用ArrayAdaptersは次のように見える傾向:

(ArrayListに<文字列>の名前は、ArrayListの名から作成されたArrayListのです<タスク>)

public class ArrayAdapterTask extends ArrayAdapter<String> { 

    private final Context context; 
    private int layoutId; 
    private ArrayList<Task> tasks; 

    public ArrayAdapterTask(Context context, ArrayList<String> names, ArrayList<Task> tasks, int layoutId) { 
     super(context, layoutId, names); 

     this.context = context; 
     this.tasks = null; 
     this.tasks = tasks; 
     this.layoutId = layoutId; 
    } 

    @Override 
    public View getView(int position, View view, ViewGroup parent) { 
     // Do stuff with the tasks.get(position) 
    } 
} 
関連する問題