Не удалось добавить эффект выделения TextView в ListView - PullRequest
0 голосов
/ 11 мая 2019

У меня есть ListView с его TextView следующим образом.Некоторый текст в ListView слишком длинный, поэтому я хочу, чтобы он прокручивался горизонтально.

<ListView
        android:id="@+id/food_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="16dp"
        android:background="@drawable/border_background" />
<TextView
        android:id="@+id/food_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="@color/black"
        android:textSize="14sp" />

Внутри моего addTextChangedListener у меня есть следующий код (список будет меняться при поиске в EditTextaccorindly).Однако каждый элемент TextView внутри ListView находится всего в одной строке, но не прокручивается по горизонтали.Используя System.out.println(foodName.getText()), я могу получить все имена элементов в ListView, поэтому что-то не так с foodNameText.setSelected(true); при использовании в цикле for?

myListAdapter = new SimpleAdapter(AddNewFoodActivity.this, foodListArray, R.layout.food_list_view, colHEAD, dataCell);
                                        foodList.setAdapter(myListAdapter);

int count = foodList.getAdapter().getCount();
for (int i = 0; i < count; i++) {
    TextView foodNameText = (TextView) foodList.getAdapter().getView(i, null, 
                         foodList).findViewById(R.id.food_item);
    foodNameText.setSelected(true);                                      
    //System.out.println(foodName.getText());
}

1 Ответ

0 голосов
/ 11 мая 2019

Попробуйте этот код:

<TextView
      android:id="@+id/toolbar_title"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:singleLine="true"
      android:text="Your text" />


foodNameText.setEllipsize(TextUtils.TruncateAt.MARQUEE);
foodNameText.setHorizontallyScrolling(true);
foodNameText.setMarqueeRepeatLimit(-1);
foodNameText.setFocusable(true);
foodNameText.setFocusableInTouchMode(true);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...