Issues with highlighted mouse elements on Ellipsize with the currently selected list item

My question is . I want the text of the TextView that I had in the custom ListView to appear only when the item is selected in the ListView. When a list item loses focus, I want the selection to stop scrolling. I know that I need to set the TextView to enable ( setEnabled (true) ) to scroll to work, but when I do this as I add elements, they ALL scroll, and this is not the behavior I want (but it makes sense, Why is this happening). I tried setting them up programmatically using a ListView click handler to enable TextView ( setEnabled (true)), track the currently selected item in a private variable, and then vice versa set previous views. The status of the TextView element is turned on as false when a new element is clicked and so on. I hope this makes sense. Here is some Java code that can better illustrate it:

    private View tempListItemView = null;

    if (this.tempListItemView != null) {
       TextView tempTxtView = (TextView) tempListItemView.findViewById(R.id.txtArticleTitle);
       tempTxtView.setSelected(false);
       tempTxtView.setEllipsize(TruncateAt.END);
    }
    // Set marquee of currently selected list item
    TextView tt = (TextView) v.findViewById(R.id.txtArticleTitle);
    tt.setEllipsize(TruncateAt.MARQUEE);
    tt.setSelected(true);
    tempListItemView = v; 

, . . , , , , listSelector, (. ). , - , TextView ( ListView ListSelector . , Droid. , , . , . .

ListActivity, ArrayAdapter . , , :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:listSelector="@drawable/list_selector"
    />
</LinearLayout>

list_selector :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_focused="true" android:drawable ="@drawable/maroon_list_select_bg" />
  <item android:drawable="@drawable/maroon_list_select_bg" />
</selector>

Drawable - 11- , - . , : ( , : (

, ( TextView)...

            <TextView
                android:id="@+id/txtArticleTitle"
                android:textSize="16sp"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/list_item"
                android:singleLine="true"
                android:ellipsize="end">  
            </TextView>
            <TextView
                android:id="@+id/txtArticleSnippet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/list_desc_copy"
                >
            </TextView>
            <TextView
                android:id="@+id/txtArticleVotes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Votes: 1576"
                android:textColor="@color/list_small_copy"
                >
            </TextView>

, , , android: "marquee", , , , .

- ? , ... . !

+3
2

TextView:: New TextView::? onTouchEvent(MotionEvent event) , . , ,

super.onTouchEvent(MotionEvent event);

onKeyDown(int keyCode, KeyEvent event)

onTrackballEvent(MotionEvent event)

XML

0

, setSelected (true).

GridView ( ListView). setOnItemClickListener:

gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            v.setSelected(true);

            // FIXME - text not align in the background
            Toast.makeText(getSherlockActivity()
                    , "click " + SHOWN_TRACKED_ITEMS.get(position).name, Toast.LENGTH_SHORT).show();
        }
    });

, , , , , . , .

, gif.

0

Source: https://habr.com/ru/post/1763149/


All Articles