Textview не прокручивается при асинхронном вызове

У меня странная "ошибка", когда я могу видеть текстовую прокрутку, только если я открываю приложение из списка приложений или возвращаюсь назад с помощью кнопки "назад" на Android, но не в том случае, если я использую собственную кнопку "Назад" внутри приложения или поворачиваю экран. Вот соответствующий код:

//this override the implemented method from asyncTask
@Override
public void processFinish(final Object output){
    //Here you will receive the result fired from async class
    //of onPostExecute(result) method.

   //some irrelevant code here

        LinearLayout mainRSSLayout = (LinearLayout) findViewById(R.id.main_rss_layout);

        RelativeLayout relativeLayoutFeed = createRSSFeed(output, i);


            //plug in
            linearLayoutFeedPair.addView(relativeLayoutFeed, linearLayoutFeedPairParam);
            linearLayoutFeedPair.addView(relativeLayoutFeed2, linearLayoutFeedPairParam);
            mainRSSLayout.addView(linearLayoutFeedPair);

        mainRSSLayout.addView(relativeLayoutFeed);

}

и фактическое программное создание:

private RelativeLayout createRSSFeed(Object output, int i){
    int height = dpToPx(this, 200); 

    /** FEED FRAME */
    RelativeLayout relativeLayoutFeed = new RelativeLayout(this);
    RelativeLayout.LayoutParams relativeLayoutFeedParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height);
    relativeLayoutFeed.setLayoutParams(relativeLayoutFeedParams);
    relativeLayoutFeed.setBackgroundColor(Color.GRAY);
    relativeLayoutFeed.setPadding(0, dpToPx(this, 3), 0, 0);
    //relativeLayoutFeed.setId(R.id.reservedRelativeLayoutRSSFeedId + i-1);
    relativeLayoutFeed.setId(R.id.reservedRelativeLayoutRSSFeedId);
    relativeLayoutFeed.setOnTouchListener(this);


    /** FEED TEXT FRAME */
    RelativeLayout relativeLayout_subText = new RelativeLayout(this);

    /** TITLE */
    TextView textViewTitle = new TextView(this);

    textViewTitle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(this, 30)));

    textViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, dpToPx(this, 24));


    // TITLE SCROLLING <- the problem?
        textViewTitle.setSingleLine(true);
        textViewTitle.setHorizontallyScrolling(true);
        textViewTitle.setMarqueeRepeatLimit(-1);
        textViewTitle.setEllipsize(TextUtils.TruncateAt.MARQUEE);

        textViewTitle.setFocusableInTouchMode(true);
        textViewTitle.setFocusable(true);
        textViewTitle.requestFocus();

        textViewTitle.setSelected(true); 


    textViewTitle.setTypeface(null, Typeface.BOLD);
    textViewTitle.setTextColor(Color.WHITE);
    textViewTitle.setPadding(dpToPx(this, 5), 0, dpToPx(this, 5), 0);
    textViewTitle.setText("Lorem Ipsum");
    textViewTitle.setText(fromHtml(((List<Entry>)output).get(i-1).title));
    /** BODY */
    TextView textViewBody = new TextView(this);
    textViewBody.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(this, 30)));//50px
    //textViewBody.setTextSize(dpToPx(this, 5)); //10px
    textViewBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, dpToPx(this, 12));
    textViewBody.setMaxLines(2);
    textViewBody.setTextColor(Color.WHITE);
    textViewBody.setPadding(dpToPx(this, 3), 0, dpToPx(this, 3), 0);
    textViewBody.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.");
    textViewBody.setText(fromHtml(((List<Entry>)output).get(i-1).description));



    linearLayout_subText.addView(textViewTitle);
    linearLayout_subText.addView(textViewBody);


    return relativeLayoutFeed;
}

1 ответ

Очевидно, это работает, если вы не вызываете onStart() перед выполнением асинхронных задач, поэтому я решил проблему с помощью:

public void onStart () {
    SystemClock.sleep(1000);
    super.onStart();


    System.out.println("on start");
}
Другие вопросы по тегам