0

In my application I have inflate two layouts in one common scroll layout one by one as follows for showing json result.

common scroll layout.

layout1 layout2

layout1 layout2

layout1 layout2

.......

layout1 and layout2 has some EditText,Textview,buttons.

like a message and reply system. I need to get position no of layout2's buttons,textviews.. but my code always return zero for position for layout2 UI. Layout1 is working fine.

this is my sample code:

for (int i = 0; i < resultSize; i++) {
   // layout 1
   LayoutInflater mInflater = LayoutInflater.from(referenceActivity);
   final View row = mInflater.inflate(R.layout.comments_list_item, null);  
    // ... adding buttons and other widgets

   // layout2

   for (int j = 0; j < replyCount; j++) {

     LayoutInflater reply_mInflater = LayoutInflater.from(referenceActivity);
     final View reply_row = reply_mInflater.inflate(R.layout.commets_list_item_replay,null);

     // ... adding UI widgets       

    comments_reply_layout.addView(reply_row);

       for (int index = 0; index < comments_reply_layout.getChildCount(); index++) {
           final View reply_row_click = comments_reply_layout.getChildAt(index);

           reply_delete = (Button) reply_row_click.findViewById(R.id.comm_reply_delete);

           reply_delete.setOnClickListener(new OnClickListener() {
           @Override
           public void onClick(View v) {

            globalRowCount = comments_reply_layout.indexOfChild(reply_row_click);
            Log.i("position" , ""+globalRowCount);  // always return zero even if more than 1 present.
              }
             });
      }
    }
} 

I have spend a day but i could not find out the problem. please help me to solve.

4

0 回答 0