I want to make a list, by scrolling which, the elements became in a certain position and the text of these elements became larger and could be edited.

The list should look something like this: enter image description here

Should work as:

enter image description here

Those. the user scrolls our list (as in the first line) and in the second position is selected the list item (highlighted, for example, with other backgrounds and more text).

and it is necessary that the element got to the second position, it was possible to edit the text in it.

and all this should be as smooth as on the second screen ..

Tell me, how can I implement this?

Thanks in advance for your help!

Edit:

Thanks for attention

The question came out extensive initially because I wanted to show what I generally want to do in the end in order to initially choose the correct and optimal way to solve the problem.

A more specific question: how can I make a selection of a specific element (for example, the second from the top) with a different font size on the sheet? At the same time, when scrolling through the list, an element that falls into second place should change the font size.

    1 answer 1

    In order for certain list items to specify a different view, it is necessary to create, in fact, the markup itself for each type of item - how they will look and in the adapter to override two methods:

    getItemViewType(position) - contains a condition by which you can determine what kind of item to display in the current position. Returns the ID of this item.

    getViewTypeCount() - returns the number of items of various types.

    Create a simple list with two types of items: item_normal.xml - the general view and item_big.xml - the view with a larger font (the font size is set directly in the markup). I will not invent the markings themselves - they have to implement what items for each type will look like.

    Custom adapter (the simplest example based on an ArrayAdapter is only the parts that are important for understanding):

     public class CustomAdapter extends ArrayAdapter { private LayoutInflater mInflater; private static final int TYPE_1 = 0; // ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΉΡ‚Π΅ΠΌΠ° ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ° private static final int TYPE_2 = 1; // ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΉΡ‚Π΅ΠΌΠ° Π²Ρ‚ΠΎΡ€ΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ° private ArrayList mItems; public CustomAdapter(Context context, ArrayList items) { super(context, items); mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); mItems = items; } public View getView(int position, View convertView, ViewGroup parent) { // ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π²ΠΈΠ΄Π° Π°ΠΉΡ‚Π΅ΠΌΠ° Π² Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ int type = getItemViewType(position); View v = convertView; //ΠΈΠ½Ρ„Π»Π΅ΠΉΡ‚ΠΈΠΌ Ρ€Π°Π·ΠΌΠ΅Ρ‚ΠΊΡƒ Π°ΠΉΡ‚Π΅ΠΌΠ° для Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ switch (type) { case TYPE_1: v = mInflater.inflate(R.layout.item_normal, null); break; case TYPE_2: v = mInflater.inflate(R.layout.item_big, null); break; default: } // Если Π°ΠΉΡ‚Π΅ΠΌΡ‹ Ρ€Π°Π·Π½Ρ‹Ρ… Π²ΠΈΠ΄ΠΎΠ² содСрТат Ρ€Π°Π·Π½Ρ‹Π΅ Π΄Π°Π½Π½Ρ‹Π΅ для отобраТСния // Ρ‚ΠΎ раздСляСм Π±ΠΈΠ½Π΄ΠΈΠ½Π³: // // switch (type) // { // case TYPE_1: // Π±ΠΈΠ½Π΄ΠΈΠ½Π³ Π΄Π°Π½Π½Ρ‹Ρ… Π² Π°ΠΉΡ‚Π΅ΠΌ ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ Π²ΠΈΠ΄Π°. // // break; // case TYPE_2: // Π±ΠΈΠ½Π΄ΠΈΠ½Π³ Π΄Π°Π½Π½Ρ‹Ρ… Π² Π°ΠΉΡ‚Π΅ΠΌ Π²Ρ‚ΠΎΡ€ΠΎΠ³ΠΎ Π²ΠΈΠ΄Π°. // // break; // } // // Π’Π°ΠΊ ΠΊΠ°ΠΊ Π² вашСм случаС Π΄Π°Π½Π½Ρ‹Π΅ Π² Π°ΠΉΡ‚Π΅ΠΌΠ°Ρ… Π½Π΅ ΠΌΠ΅Π½ΡΡŽΡ‚ΡΡ, Ρ‚ΠΎ для ΠΎΠ±ΠΎΠΈΡ… // Π±ΠΈΠ½Π΄ΠΈΠ½Π³ ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²Ρ‹ΠΉ ΠΈ Π΅Π³ΠΎ Π½Π΅ Π½ΡƒΠΆΠ½ΠΎ Ρ€Π°Π·Π΄Π΅Π»ΡΡ‚ΡŒ. String text = mItems.get(position); // ΠΈΠ·Π²Π»Π΅ΠΊΠ°Π΅ΠΌ Π΄Π°Π½Π½Ρ‹Π΅ TextView tv = (TextView) v.findViewById(R.id.text); tv.setText(text); // Ρ€Π°Π·ΠΌΠ΅Ρ‰Π°Π΅ΠΌ Π² Π°ΠΉΡ‚Π΅ΠΌ return v; } @Override public int getItemViewType(int position) { // Π—Π΄Π΅ΡΡŒ Π½ΡƒΠΆΠ½ΠΎ ΠΎΠΏΡ€Π΅Π΄Π΅Π»ΠΈΡ‚ΡŒ Π²Ρ‚ΠΎΡ€ΡƒΡŽ Π²ΠΈΠ΄ΠΈΠΌΡƒΡŽ ΠΏΠΎΠ·ΠΈΡ†ΠΈΡŽ // ΠΈ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΉΡ‚Π΅ΠΌΠ° Π²Ρ‚ΠΎΡ€ΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ° // ΠΈΠ½Π°Ρ‡Π΅ - Π°ΠΉΡ‚Π΅ΠΌΠ° ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ° // Надо ΠΏΠΎΠ΄ΡƒΠΌΠ°Ρ‚ΡŒ. return (twoPosition) ? TYPE_2 : TYPE_1; } @Override public int getViewTypeCount() { return 2; // Π΄Π²Π° Ρ€Π°Π·Π»ΠΈΡ‡Π½Ρ‹Ρ… Π²ΠΈΠ΄Π° Π°ΠΉΡ‚Π΅ΠΌΠΎΠ² } } 

    Since in your case, the appearance of different items is no different than anything other than the color and size of the font, you specify all these differences directly in the markup - you do not need to bind the data separately.
    In more complex cases, you can use any independent data for different types of items, which can contain completely different markup and share their content through a switch - case in a commented block.

    In a real adapter it is better to use holders and other optimizations.

    • Made the adapter to the list. True, inherited from BaseAdapter. Now the problem is that I can’t figure out how to make one element seem to be in place and only a list item will be inserted into it. This is the problem that you wrote about with comments "// Here you need to determine the second visible position // and return the identifier of the second type item // otherwise - the first type item // Need to think." Perhaps you have some ideas on how to implement this? - researcher
    • I am now thinking about your task and it was initially set incorrectly. Simple customization of ListView does not solve it. Most likely, you need to implement something based on this library , but not with strings, but with item threads. - pavlofff
    • And so, if you continue to β€œtorment” ListView , it has a method getFirstVisiblePosition() , which returns the number of that position in the adapter, which is in the first visible position of the list. From the adapter’s side, this doesn’t seem to be implemented, and my answer cannot be considered correct. - pavlofff
    • Still this libu can be studied. Sources on GitHub - pavlofff