2016-08-22 108 views
0

我曾與editTextView和TextView的一個haderListView: 當我點擊添加圖標,我添加了一個列表至極我可以填補空editTextView, 的問題來了,當我加入項目2清單:當我開始完成第一個清單,我發現第二個清單採用了相同的數據, 我如何分配每個清單的項目。添加EDITTEXT在HeaderListView安卓

第一個List,我把測試在fonction enter image description here

在Seconde系列列表中我發現,從第一個

tooks數據

enter image description here

我的問題如何是否有分離形式?

這是我的適配器:

public class SectionAuthorAdapter extends com.applidium.headerlistview.SectionAdapter { 

    private MainActivity mainActivity; 
    private Realm realm; 
    private Author author = null; 
    private Authors_groups authors_groups = null; 
    private RealmList<Author> authors = new RealmList<>(); 
    int num= 0; 
    private List<Authors_groups> authors_groupses; 

    public SectionAuthorAdapter(MainActivity mainActivity, List<Authors_groups> authors_groupses) { 

     this.mainActivity = mainActivity; 
     realm = Realm.getInstance(mainActivity); 


     this.authors_groupses = authors_groupses; 
    } 

    @Override 
    public int numberOfSections() { 
     return authors_groupses.size(); 
    } 

    @Override 
    public int numberOfRows(int section) 
    { 
     if(section == -1) 
      section = 0; 
     return authors_groupses.get(section).getAuthors().size(); 
    } 

    @Override 
    public View getRowView(int section, int row, View convertView, ViewGroup parent) { 
     final int id ; 
     //ViewHolder holder = null; 
     final ViewHolder holder; 

     if (convertView == null) { 

      holder = new ViewHolder(); 
      LayoutInflater inflater = mainActivity.getLayoutInflater(); 
      convertView = inflater.inflate(R.layout.listview_item_agent, null); 
      holder.textView1 = (TextView) convertView.findViewById(R.id.textView1); 
      holder.editText1 = (EditText) convertView.findViewById(R.id.editText1); 


      convertView.setTag(holder); 

     } else { 

      holder = (ViewHolder) convertView.getTag(); 
     } 
     realm.beginTransaction(); 

     id = authors_groupses.get(section).getAuthors().get(row).getId(); 
     authors_groups = new Authors_groups(); 

     author = authors_groupses.get(section).getAuthors().get(row); 
     if (author != null) { 
      holder.textView1.setText(author.getField().getLabel() + " : "); 
      if (author.getData() != null && !author.getData().isEmpty()) 
      { 
       holder.editText1.setText(author.getData()); 
      } 
      holder.editText1.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        holder.editText1.getId(); 
       } 
      }); 


     authors.add(author); 
     authors_groups.setAuthors(authors); 
     } 
     realm.commitTransaction(); 
     return convertView; 
    } 

    @Override 
    public Object getRowItem(int section, int row) { 
     return null; 
    } 

    @Override 

    public View getSectionHeaderView(int section, View convertView, ViewGroup parent) { 

     if (convertView == null) { 

       convertView = (TextView) mainActivity.getLayoutInflater().inflate(mainActivity.getResources().getLayout(android.R.layout.simple_list_item_1), null); 

     } 
       section = section+1; 
      ((TextView) convertView).setText("Témoin : " +section); 

convertView.setBackgroundColor(mainActivity.getResources().getColor(R.color.android_green)); 


     return convertView; 
    } 
    @Override 
    public boolean hasSectionHeaderView(int section) { 
     return true; 
    } 

    @Override 
    public void onRowItemClick(AdapterView<?> parent, View view, int section, int row, long id) { 
     super.onRowItemClick(parent, view, section, row, id); 

    } 

    class ViewHolder { 
     TextView textView1; 
     EditText editText1; 

    } 
} 

回答

0

我想你應該設置適配器之前,每次啓動新的適配器。

SectionAuthorAdapter sectionAuthorAdapter; 

sectionAuthorAdapter = new SectionAuthorAdapter (mainActivity,authors_groupses); 
yourListView1.setAdapter(sectionAuthorAdapter); 

sectionAuthorAdapter = new SectionAuthorAdapter (mainActivity,authors_groupses); 
yourListView2.setAdapter(sectionAuthorAdapter); 

。:: UPDATE ::。

public class HomeActivity extends AppCompatActivity 
     implements NavigationView.OnNavigationItemSelectedListener { 
    HorizontalGridView newHorizontalGridView,popularHorizontalGridView,unreleasedHorizontalGridView; 
    PopularGridElementAdapter popularAdapter; 
    PopularGridElementAdapter unreleasedGridElementAdapter; 
    PopularGridElementAdapter newReleasedGridElementAdapter; 
    List<PopularImageModel> popularimageModelList = new ArrayList<PopularImageModel>(); 
    List<UnreleasedImageModel> unreleasedimageModelList = new ArrayList<UnreleasedImageModel>(); 
    List<NewReleasedImageModel> newreleasedimageModelList = new ArrayList<NewReleasedImageModel>(); 

    @Override 
    protected void onCreate (Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayShowTitleEnabled(false); 

     newHorizontalGridView = (HorizontalGridView) findViewById(R.id.gridViewNewReleased); 
     popularHorizontalGridView = (HorizontalGridView) findViewById(R.id.gridViewPopular); 
     unreleasedHorizontalGridView = (HorizontalGridView) findViewById(R.id.gridViewUnreleased); 
     popularAdapter = new PopularGridElementAdapter(this, popularimageModelList); 
     unreleasedGridElementAdapter = new PopularGridElementAdapter(this, unreleasedimageModelList); 
     newReleasedGridElementAdapter = new PopularGridElementAdapter(this, newreleasedimageModelList); 

     newHorizontalGridView.setAdapter(newReleasedGridElementAdapter); 
     popularHorizontalGridView.setAdapter(popularAdapter); 
     unreleasedHorizontalGridView.setAdapter(unreleasedGridElementAdapter); 

     parsePopularImages(); 
     parseUnreleasedImages(); 
     parseNewReleasedImages(); 

//  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
//  fab.setOnClickListener(new View.OnClickListener() { 
//   @Override 
//   public void onClick(View view) { 
//    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
//      .setAction("Action", null).show(); 
//   } 
//  }); 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setNavigationItemSelectedListener(this); 



    } 

    @Override 
    public void onBackPressed() { 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     if (drawer.isDrawerOpen(GravityCompat.START)) { 
      drawer.closeDrawer(GravityCompat.START); 
     } else { 
      super.onBackPressed(); 
     } 
    } 



    @SuppressWarnings("StatementWithEmptyBody") 
    @Override 
    public boolean onNavigationItemSelected (MenuItem item) { 
     // Handle navigation view item clicks here. 
     int id = item.getItemId(); 

     if (id == R.id.nav_camera) { 
      // Handle the camera action 
     } else if (id == R.id.nav_gallery) { 

     } else if (id == R.id.nav_slideshow) { 

     } else if (id == R.id.nav_manage) { 

     } else if (id == R.id.nav_share) { 

     } else if (id == R.id.nav_send) { 

     } 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     drawer.closeDrawer(GravityCompat.START); 
     return true; 
    } 


    public void parsePopularImages() { 


     JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(AppController.TAG_POPULAR_IMAGES, new Response.Listener<JSONArray>() { 
      @Override 
      public void onResponse (JSONArray response) { 

       for (int i = 0; i < response.length(); i++) { 
        try { 
         JSONObject obj = response.getJSONObject(i); 

         PopularImageModel model = new PopularImageModel(); 

         model.setSinger_id(obj.getString("singer_id")); 
         model.setImage(obj.getString("image")); 
         model.setName(obj.getString("name")); 

         popularimageModelList.add(model); 


        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
       popularAdapter.notifyDataSetChanged(); 
      } 
     }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse (VolleyError error) { 

        } 
       }); 
     jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
       (int) TimeUnit.SECONDS.toMillis(20), 
       DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
     AppController.getInstance().addToRequestQueue(jsonArrayRequest); 
    } 

    public void parseUnreleasedImages() { 


     JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(AppController.TAG_UNRELEASED_IMAGES, new Response.Listener<JSONArray>() { 
      @Override 
      public void onResponse (JSONArray response) { 

       for (int i = 0; i < response.length(); i++) { 
        try { 
         JSONObject obj = response.getJSONObject(i); 

         UnreleasedImageModel model = new UnreleasedImageModel(); 

         model.setSinger_id(obj.getString("singer_id")); 
         model.setImage(obj.getString("image")); 
         model.setName(obj.getString("name")); 

         unreleasedimageModelList.add(model); 


        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
       unreleasedGridElementAdapter.notifyDataSetChanged(); 
      } 
     }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse (VolleyError error) { 

        } 
       }); 
     jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
       (int) TimeUnit.SECONDS.toMillis(20), 
       DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 

     AppController.getInstance().addToRequestQueue(jsonArrayRequest); 
    } 

    public void parseNewReleasedImages() { 


     JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(AppController.TAG_NEW_RELEASED_IMAGES, new Response.Listener<JSONArray>() { 
      @Override 
      public void onResponse (JSONArray response) { 

       for (int i = 0; i < response.length(); i++) { 
        try { 
         JSONObject obj = response.getJSONObject(i); 

         NewReleasedImageModel model = new NewReleasedImageModel(); 

         model.setSinger_id(obj.getString("singer_id")); 
         model.setImage(obj.getString("image")); 
         model.setName(obj.getString("name")); 

         newreleasedimageModelList.add(model); 


        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
       newReleasedGridElementAdapter.notifyDataSetChanged(); 
      } 
     }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse (VolleyError error) { 

        } 
       }); 

     jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
       (int) TimeUnit.SECONDS.toMillis(20), 
       DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 

     AppController.getInstance().addToRequestQueue(jsonArrayRequest); 
    } 
} 
+0

謝謝,但它不工作。 – Euphor08

+0

但這種方法從我工作:( – Rifan

+0

你可以給我一部分的代碼? – Euphor08