{"id":185004,"date":"2013-06-28T17:15:03","date_gmt":"2013-06-28T13:15:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=185004"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=185004","title":{"rendered":"<span class=\"post_title\">\u0421\u043e\u0437\u0434\u0430\u0435\u043c ListView \u0441 Context Action Bar \u043a\u0430\u043a \u0432 \u043d\u043e\u0432\u043e\u043c Gmail<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/bd2\/098\/6ac\/bd20986ac92498d972d0d169610e59f8.png\"\/><\/p>\n<h4>\u0427\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<\/h4>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043b\u0430\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u044f\u0434\u043e\u0432 \u043a\u0430\u043a \u043a\u043b\u0438\u043a\u043e\u043c \u043d\u0430 \u0438\u043a\u043e\u043d\u043a\u0443 \u0440\u044f\u0434\u0430, \u0442\u0430\u043a \u0438 \u0434\u043e\u043b\u0433\u0438\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435\u043c \u043d\u0430 \u043d\u0435\u0433\u043e. \u0422\u0430\u043a\u0436\u0435, \u0434\u0430\u0431\u044b \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u043b\u043e \u0434\u0430\u0440\u043e\u043c, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u0430<\/h4>\n<p>  \u0418\u0442\u0430\u043a, \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c layout, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0442\u0430\u043a:<\/p>\n<pre><code class=\"xml\">&lt;RelativeLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;                 xmlns:tools=&quot;http:\/\/schemas.android.com\/tools&quot;                 android:layout_width=&quot;match_parent&quot;                 android:layout_height=&quot;match_parent&quot;                 android:paddingLeft=&quot;@dimen\/activity_horizontal_margin&quot;                 android:paddingRight=&quot;@dimen\/activity_horizontal_margin&quot;                 android:paddingTop=&quot;@dimen\/activity_vertical_margin&quot;                 android:paddingBottom=&quot;@dimen\/activity_vertical_margin&quot;                 tools:context=&quot;.MainActivity&quot;&gt;      &lt;ListView             android:id=&quot;@android:id\/list&quot;             android:layout_width=&quot;fill_parent&quot;             android:layout_height=&quot;fill_parent&quot;\/&gt;  &lt;\/RelativeLayout&gt; <\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u0434\u0438\u043d\u0433\u043e\u0432, \u043b\u044e\u0431\u0435\u0437\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043c\u0435\u043d\u044f <a href=\"http:\/\/developer.android.com\/sdk\/installing\/studio.html\">android developer studio<\/a>, \u0437\u0434\u0435\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u043d\u0435\u0442. \u0420\u0430\u0437\u0432\u0435 \u0447\u0442\u043e \u043d\u0430\u043f\u043e\u043c\u043d\u044e: <b>android:id\/list<\/b> \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 ID, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u043d\u0430\u044e\u0442 ListActivity \u0438 ListFragment.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c layout, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u043c \u0440\u044f\u0434\u043e\u043c \u0432 \u043d\u0430\u0448\u0435\u043c ListView:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;RelativeLayout         xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;         android:layout_width=&quot;match_parent&quot;         android:layout_height=&quot;match_parent&quot;         android:orientation=&quot;vertical&quot;         android:background=&quot;?android:attr\/activatedBackgroundIndicator&quot;&gt;      &lt;View             android:id=&quot;@+id\/item_image&quot;             android:layout_width=&quot;45dp&quot;             android:layout_height=&quot;45dp&quot;             android:layout_margin=&quot;5dp&quot;             android:padding=&quot;10dp&quot;\/&gt;      &lt;TextView             android:id=&quot;@+id\/item_text&quot;             android:layout_width=&quot;wrap_content&quot;             android:layout_height=&quot;wrap_content&quot;             android:layout_toRightOf=&quot;@id\/item_image&quot;             android:layout_marginTop=&quot;10dp&quot;             android:layout_marginLeft=&quot;10dp&quot;             android:text=&quot;TextView&quot;             android:layout_gravity=&quot;center_vertical|left&quot;             android:textAppearance=&quot;?android:textAppearanceListItem&quot;&gt;     &lt;\/TextView&gt; &lt;\/RelativeLayout&gt; <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 TextView, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 View. \u041d\u0430 \u043c\u0435\u0441\u0442\u0435 View \u043e\u0431\u044b\u0447\u043d\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0446\u0432\u0435\u0442. <br \/>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 <b>android:background=&quot;?android:attr\/activatedBackgroundIndicator&quot;<\/b> \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 layout. \u0411\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u043d \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u0435\u043c ListView \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0435\u0433\u043e<\/h4>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434 activity, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u044f\u0441\u043d\u044e \u0435\u0433\u043e:  <\/p>\n<pre><code class=\"java\">public class MainActivity extends ListActivity {     public static final String TAG = &quot;FOR_HABR&quot;;     private Random randomGenerator = new Random();      @Override     protected void onCreate(Bundle savedInstanceState) {         Log.d(TAG, &quot;onCreate&quot;);         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          \/\/\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u0441\u0442\u0430         int size = getRandomNumber(200);          ListView listView = getListView();         \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430         Integer[] colors = generateListOfColors(size).toArray(new Integer[0]);         ArrayAdapter&lt;Integer&gt; customAdapter = new CustomAdapter(this, R.layout.list_view_row, colors, listView);         listView.setAdapter(customAdapter);     }      @Override     public boolean onCreateOptionsMenu(Menu menu) {         Log.d(TAG, &quot;onCreateOptionsMenu&quot;);         getMenuInflater().inflate(R.menu.main, menu);         return true;     }      \/\/\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432     private List&lt;Integer&gt; generateListOfColors(int size) {         List&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();         for (int i = 0; i &lt; size; i++) {             result.add(generateRandomColor());         }         return result;     }      \/\/\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0446\u0432\u0435\u0442     private int generateRandomColor() {         return Color.rgb(getRandomNumber(256), getRandomNumber(256), getRandomNumber(256));     }      private int getRandomNumber(int maxValue) {         return randomGenerator.nextInt(maxValue);     }  } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e ID layout, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d \u043d\u0430\u0448 \u043b\u0438\u0441\u0442, \u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c \u044d\u0442\u043e\u0433\u043e activity. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c ListView \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u043c\u044b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u0447\u0438\u0441\u0435\u043b \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430. <br \/>  \u0410\u0434\u0430\u043f\u0442\u0435\u0440 \u2014 \u044d\u0442\u043e \u043c\u043e\u0441\u0442 \u043c\u0435\u0436\u0434\u0443 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u0432 \u043d\u0435\u043c \u043c\u044b \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0433\u0434\u0435 \u0438 \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u044f\u0434\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430:  <\/p>\n<pre><code class=\"java\">public class CustomAdapter extends ArrayAdapter&lt;Integer&gt; {     private ListView listView;      public CustomAdapter(Context context, int textViewResourceId, Integer[] objects, ListView listView) {         super(context, textViewResourceId, objects);         this.listView = listView;     }      static class ViewHolder {         TextView text;         View indicator;     }      @Override     public View getView(final int position, View convertView, ViewGroup parent) {         Integer color = getItem(position);          View rowView = convertView;          \/\/\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b         if (rowView == null) {             LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();             rowView = inflater.inflate(R.layout.list_view_row, parent, false);             ViewHolder h = new ViewHolder();             h.text = (TextView) rowView.findViewById(R.id.item_text);             h.indicator = rowView.findViewById(R.id.item_image);             rowView.setTag(h);         }          ViewHolder h = (ViewHolder) rowView.getTag();          h.text.setText(&quot;#&quot; + Integer.toHexString(color).replaceFirst(&quot;ff&quot;, &quot;&quot;));         h.indicator.setBackgroundColor(color);          return rowView;     } } <\/code><\/pre>\n<p>  \u041c\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u043c\u0435\u0442\u043e\u0434 getView. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0432 \u043f\u043e\u043b\u0435 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0440\u044f\u0434 \u0441\u043f\u0438\u0441\u043a\u0430. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438\u0437 \u043d\u0435\u0433\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 View \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0436\u0435\u043b\u0430\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<br \/>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e (\u0434\u043e 15%) \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c ListView \u0437\u0430 \u0441\u0447\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u043e\u0436\u043d\u043e <a href=\"http:\/\/developer.android.com\/training\/improving-layouts\/smooth-scrolling.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0438 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u0446\u0432\u0435\u0442\u0430\u043c\u0438, \u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u0430.<\/p>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u0430 \u0440\u044f\u0434\u0430<\/h4>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:  <\/p>\n<pre><code class=\"java\">\/\/\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c ListView, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0435\u0436\u0438\u043c \u0441 \u043c\u0443\u043b\u044c\u0442\u0438\u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); \/\/\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u0430 listView.setMultiChoiceModeListener(new MultiChoiceImpl(listView)); <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"java\">public class MultiChoiceImpl implements AbsListView.MultiChoiceModeListener {     private AbsListView listView;      public MultiChoiceImpl(AbsListView listView) {         this.listView = listView;     }      @Override     \/\/\u041c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u044f\u0434\u043e\u0432     public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {         Log.d(MainActivity.TAG, &quot;onItemCheckedStateChanged&quot;);         int selectedCount = listView.getCheckedItemCount();         \/\/\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0432 Context Action Bar         setSubtitle(actionMode, selectedCount);     }      @Override     \/\/\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u0434\u0443\u0432\u0430\u0435\u043c CAB \u0438\u0437 xml     public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {         Log.d(MainActivity.TAG, &quot;onCreateActionMode&quot;);         MenuInflater inflater = actionMode.getMenuInflater();         inflater.inflate(R.menu.context_menu, menu);         return true;     }      @Override     public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {         Log.d(MainActivity.TAG, &quot;onPrepareActionMode&quot;);         return false;     }      @Override    \/\/\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 Item \u0438\u0437 \u0421AB     public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {         String text = &quot;Action - &quot; + menuItem.getTitle() + &quot; ; Selected items: &quot; + getSelectedFiles();         Toast.makeText(listView.getContext(), text , Toast.LENGTH_LONG).show();         return false;     }      @Override     public void onDestroyActionMode(ActionMode actionMode) {         Log.d(MainActivity.TAG, &quot;onDestroyActionMode&quot;);     }      private void setSubtitle(ActionMode mode, int selectedCount) {         switch (selectedCount) {             case 0:                 mode.setSubtitle(null);                 break;             default:                 mode.setTitle(String.valueOf(selectedCount));                 break;         }     }      private List&lt;String&gt; getSelectedFiles() {         List&lt;String&gt; selectedFiles = new ArrayList&lt;String&gt;();          SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();         for (int i = 0; i &lt; sparseBooleanArray.size(); i++) {             if (sparseBooleanArray.valueAt(i)) {                 Integer selectedItem = (Integer) listView.getItemAtPosition(sparseBooleanArray.keyAt(i));                 selectedFiles.add(&quot;#&quot; + Integer.toHexString(selectedItem).replaceFirst(&quot;ff&quot;, &quot;&quot;));             }         }         return selectedFiles;     } } <\/code><\/pre>\n<p>  \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0432\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0430\u0434\u0443\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 Action Bar (context_menu). \u041e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"xml\">&lt;menu xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;&gt;     &lt;item             android:id=&quot;@+id\/cab_add&quot;             android:icon=&quot;@android:drawable\/ic_menu_add&quot;             android:orderInCategory=&quot;1&quot;             android:showAsAction=&quot;ifRoom&quot;             android:title=&quot;add&quot;\/&gt;     &lt;item             android:id=&quot;@+id\/cab_share&quot;             android:icon=&quot;@android:drawable\/ic_menu_share&quot;             android:orderInCategory=&quot;1&quot;             android:showAsAction=&quot;ifRoom&quot;             android:title=&quot;share&quot;\/&gt; &lt;\/menu&gt; <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443. \u0412 ListView \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u2014 <b>CHOICE_MODE_MULTIPLE_MODAL<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0434\u0441\u0443\u043d\u0435\u043c ListView \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <b>AbsListView.MultiChoiceModeListener<\/b>. \u0412 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u043a\u043b\u0438\u043a\u0430 \u043f\u043e item \u0432 CAB \u0438\u043b\u0438 \u043d\u0430 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 CAB.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u044f\u0434\u0430 \u043f\u043e \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 \u0438\u043a\u043e\u043d\u043a\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 getView OnClickListener:  <\/p>\n<pre><code class=\"java\">h.indicator.setOnClickListener(new View.OnClickListener() {     @Override     public void onClick(View v) {         selectRow(v);     }      private void selectRow(View v) {         listView.setItemChecked(position, !isItemChecked(position));     }      private boolean isItemChecked(int pos) {         SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();         return sparseBooleanArray.get(pos);     } }); <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0440\u044f\u0434 \u0443\u0436\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d, \u0441\u043d\u0438\u043c\u0430\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0443 \u043c\u0435\u043d\u044f \u043d\u0430 <a href=\"https:\/\/bitbucket.org\/andrey_kidinov\/cab-example\/src\/4e9ee3655ee8\/ForHabr?at=default\">BitBucket<\/a>. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/185004\/\"> http:\/\/habrahabr.ru\/post\/185004\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/bd2\/098\/6ac\/bd20986ac92498d972d0d169610e59f8.png\"\/><\/p>\n<h4>\u0427\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c<\/h4>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043b\u0430\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u044f\u0434\u043e\u0432 \u043a\u0430\u043a \u043a\u043b\u0438\u043a\u043e\u043c \u043d\u0430 \u0438\u043a\u043e\u043d\u043a\u0443 \u0440\u044f\u0434\u0430, \u0442\u0430\u043a \u0438 \u0434\u043e\u043b\u0433\u0438\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0435\u043c \u043d\u0430 \u043d\u0435\u0433\u043e. \u0422\u0430\u043a\u0436\u0435, \u0434\u0430\u0431\u044b \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u043b\u043e \u0434\u0430\u0440\u043e\u043c, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-185004","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185004"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185004\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}