Question

I am trying to populate data in UI fetched through REST service. The data comes up everytime but the UI doesn't get populated sometimes. The UI is kind of listing but listview is not being used. There's a ScrollView which has LinearLayout as its child and then row views are added to the linearlayout. There are times when UI just doesn't get updated even if the data is passed to it.

private void showData(List list) {  
if(list != null && list.isEmpty()) {
    mNoData.setVisibility(View.VISIBLE);
} else {
    mNoData.setVisibility(View.GONE);

    final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.details_layout);

    findViewById(R.id.details_progress).setVisibility(View.GONE);

    linearLayout.removeAllViews();
    LayoutInflater layoutInflater = getLayoutInflater();
    View rowView = null;
    TextView txtName = null;
    Button buttonPlay = null;

    for (int i = 0; i < list.size(); i++) {
        rowView = layoutInflater.inflate(R.layout.row_view, null);
        txtName = (TextView) rowView.findViewById(R.id.row_view_name);
        buttonPlay = (Button) rowView.findViewById(R.id.row_view_button_play);
        final Item item = (Item) list.get(i);
        rowView.setTag(i) ;
        txtName.setText(item.getName());
        final RecentItem recentItem = RecentsManager.getInstance().getRecentItemFromRefID(item.getId());

        if (recentItem !=null) {
            buttonPlay.setText(getString("Resume"));
            buttonPlay.requestFocus();
        }

        buttonPlay.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (recentItem!=null) {
                    //do some action
                } else {
                    //do some action
                }

                finish();
            }
        });

        final int tag = (Integer) rowView.getTag() ;
        rowView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //do some action
            }
        }) ;

        txtName.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //do some action
            }
        });

        buttonPlay.setId(i);

        if(i < list.size())
            buttonPlay.setNextFocusDownId(i+1);

        linearLayout.addView(rowView);

        if (i == 0) {
            buttonPlay.requestFocus();
            buttonPlay.setNextFocusUpId(mButtonReminder.getId());

            if(mButtonReminder != null) {
                mButtonReminder.setNextFocusDownId(buttonPlay.getId());
            }   
        } else {
            buttonPlay.setNextFocusUpId(i-1);
        }
    }
}
}

I have even checked the linearlayout children's count and the count is always equal to list size which means rows are also being added to it but it just doesn't show up on the UI.

What can be the issue?

Was it helpful?

Solution 2

I was able to resolve the issue by doing certain changes as adding fillViewPort="true" for scrollview. Also, there was a background thread which was trying to update the UI because of which UI thread was breaking. This didn't resulted in a crash but the UI updation didn't happened. With these two changes it's working fine.

OTHER TIPS

you are using condition

if(list != null && list.isEmpty()) {
    mNoData.setVisibility(View.VISIBLE);
} 

change it to

if(list == null || list.isEmpty()) {
    mNoData.setVisibility(View.VISIBLE);
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top