#ExpandableListView
Explore tagged Tumblr posts
paolovecchio · 8 months ago
Text
1 note · View note
rrtutors · 2 years ago
Text
A Guide to Effortlessly Displaying Data with Android's Dynamic Expandable ListView
As cell phones keep on assuming an undeniably critical part in our day to day routines, the interest for proficient and easy to understand versatile applications has soar. One of the critical parts of any compelling portable application is the capacity to show information in a coordinated and outwardly engaging way.
In Android, the ListView is an incredible asset for showing enormous arrangements of information. Nonetheless, with regards to showing settled information, for example, classifications and subcategories, a more complex methodology is required. This is where the Dynamic Expandable ListView comes in.
A Dynamic Expandable ListView is a kind of ListView that permits clients to grow and fall things to uncover more data. This is especially valuable while managing settled information structures, as it permits clients to rapidly and effectively explore through enormous arrangements of information. In this article, we will investigate the critical elements of a Dynamic Expandable ListView in Android and give a bit by bit guide for carrying out one in your own application.
To get everything rolling, we should make a custom connector that expands the BaseExpandableListAdapter class. This connector will be liable for populating the information into the ExpandableListView. We will likewise have to make custom designs for the gathering and kid sees.
When the connector and designs are set up, we can start populating the ExpandableListView with information. This should be possible by making an information model that addresses the settled information structure. The information model ought to incorporate a rundown of parent things, every one of which contains a rundown of kid things. We can then utilize the connector to populate the ExpandableListView with this information.
One of the critical advantages of a Dynamic Expandable ListView is its adaptability. Clients can undoubtedly add or eliminate things from the rundown, and the ExpandableListView will naturally acclimate to oblige the changes.
This makes it an optimal answer for applications that arrangement with dynamic informational indexes.
Notwithstanding its adaptability, a Dynamic Expandable ListView is likewise exceptionally adjustable. Designers can without much of a stretch change the appearance and conduct of the rundown to meet the particular requirements of their application. For instance, they can change the variety plot, add movements, or carry out custom motions.
All in all, a Dynamic Expandable ListView is a fundamental instrument for any engineer hoping to show settled information structures in their Android application. With its adaptability, customization choices, and usability, an incredible asset can assist clients with exploring even the biggest arrangements of information easily.
By following the means framed in this article, designers can without much of a stretch carry out a Dynamic Expandable ListView in their own application and take their client experience to a higher level.
For More Info :-
Dynamic Expandable Listview In Android
0 notes
joeyrob1 · 5 years ago
Text
How To Add Header Footer to ExpandableListview ChildView
Contents
1 How To Add Header Footer to ExpandableListview ChildView
1.1 XML layout files
1.2 Model Classes
1.3 Custom adapter for ExpandableListView
1.4 Main activity and sample data for expandable list view
1.5 Output
2 Conclusion
How To Add Header Footer to ExpandableListview ChildView
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
(11 votes, average: 5.00 out of 5)
Tumblr media
Loading...
  I recently worked on a project, where I found it challenging initially to add a header and footer to the ExpandableListView childView. Here I document the solution I found to overcome the challenge.
Ho Ngoc Trang,  [email protected], is the author of this article and she contributes to RobustTechHouse Blog. 
  XML layout files
In order to create an expandable list view with header and footer to the child view, we will need five xml layout files. The first one is for displaying the main layout containing the ExpandableListview, the second one is for group item layout, the third is for the child item layout and the other two are for header and footer of the childview.
activity_main.xml
Open activity_main.xml layout in res/layout and add the ExpandableListView element:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ExpandableListView android:id="@+id/elv" android:layout_width="match_parent" android:layout_height="match_parent"></ExpandableListView> </RelativeLayout>
  parent_row.xml
Create another xml file for list view group header and name it as parent_row.xml and copy the following content.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:background="@color/parent_background" android:paddingLeft="@dimen/padding_left" android:layout_margin="5dp" android:layout_height="match_parent"> <TextView android:id="@+id/txtMother" android:layout_marginTop="10dp" android:textStyle="bold" android:layout_marginBottom="5dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/txtFather" android:layout_marginBottom="10dp" android:textStyle="bold" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
  child_row.xml
Create a new layout file child_row.xml in res/layout and copy the following content.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:background="@color/child_background" android:paddingLeft="@dimen/padding_left" android:layout_height="match_parent"> <TextView android:id="@+id/txtChildName" android:textColor="@android:color/holo_orange_dark" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"/> <TextView android:id="@+id/txtChildAge" android:textColor="@android:color/holo_orange_dark" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp"/> </LinearLayout>
  child_header.xml
Create a new layout file child_header.xml in res/layout and copy the following content.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/hf_background" android:paddingLeft="@dimen/padding_left"> <TextView android:id="@+id/txtHeader" android:textColor="@android:color/holo_green_light" android:layout_width="match_parent" android:gravity="center_vertical" android:textStyle="bold" android:text="Header" android:layout_height="50dp" /> </LinearLayout>
  child_footer.xml
Create a new layout file child_footer.xml in res/layout and copy the following content.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/hf_background" android:paddingLeft="@dimen/padding_left"> <TextView android:id="@+id/txtFooter" android:textColor="@android:color/holo_green_light" android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center_vertical" android:textStyle="bold" android:text="Footer" /> </LinearLayout>
  Model Classes
According to the structure of an expandable list view, we need to have at least two classes, one for the child and another one for group/parent.
ChildObject.java
ChildObject class will hold all fields displayed in the child row view.
public class ChildObject { public String childName; public int age; public ChildObject(String childName, int age) { this.childName = childName; this.age = age; } }
  ParentObject.java
ParentObject will hold all fields displayed in the group/parent row view including fields for header and footer.
public class ParentObject { public String mother; public String father; //Header and footer don’t need to be a String, //they can be a class or whatever depend on your need. public String textToHeader; public String textToFooter; //Parent should have a list of their child public List<ChildObject> childObjects; public ParentObject(String mother, String father, String textToHeader, String textToFooter, List<ChildObject> childObjects) { this.mother = mother; this.father = father; this.textToFooter = textToFooter; this.textToHeader = textToHeader; this.childObjects = childObjects; } }
  Custom adapter for ExpandableListView
This is the important part of this tutorial where we actually create the header and footer for the ExpandableListView ChildView.
We are going to create a custom adapter named MyExpandableAdapter. This class is extended from BaseExpandableListAdapter, which provides required methods to render the ExpandableListView.
Create a class and name it as MyExpandableListView, then add the following code.
public class MyExpandableAdapter extends BaseExpandableListAdapter { Context context; List<ParentObject> parentObjects; public MyExpandableAdapter(Context context, List<ParentObject> parentObjects) { this.context = context; this.parentObjects = parentObjects; } @Override public int getGroupCount() { return parentObjects.size(); } //Add 2 to childcount. The first row and the last row are used as header and footer to childview @Override public int getChildrenCount(int i) { return parentObjects.get(i).childObjects.size() +2; } @Override public ParentObject getGroup(int i) { return parentObjects.get(i); } @Override public ChildObject getChild(int i, int i2) { return parentObjects.get(i).childObjects.get(i2); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i2) { return 0; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { ParentObject currentParent = parentObjects.get(i); if(view ==null) { LayoutInflater inflater =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.parent_row,null); } TextView txtMother = (TextView)view.findViewById(R.id.txtMother); TextView txtFather = (TextView)view.findViewById(R.id.txtFather); txtMother.setText(currentParent.mother); txtFather.setText(currentParent.father); return view; } @Override public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) { ParentObject currentParent = getGroup(groupPosition); LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //the first row is used as header if(childPosition ==0) { view = inflater.inflate(R.layout.child_header, null); TextView txtHeader = (TextView)view.findViewById(R.id.txtHeader); txtHeader.setText(currentParent.textToHeader); } //Here is the ListView of the ChildView if(childPosition>0 && childPosition<getChildrenCount(groupPosition)-1) { ChildObject currentChild = getChild(groupPosition,childPosition-1); view = inflater.inflate(R.layout.child_row,null); TextView txtChildName = (TextView)view.findViewById(R.id.txtChildName); TextView txtChildAge = (TextView)view.findViewById(R.id.txtChildAge); txtChildName.setText(currentChild.childName); txtChildAge.setText("Age: " + String.valueOf(currentChild.age)); } //the last row is used as footer if(childPosition == getChildrenCount(groupPosition)-1) { view = inflater.inflate(R.layout.child_footer,null); TextView txtFooter = (TextView)view.findViewById(R.id.txtFooter); txtFooter.setText(currentParent.textToFooter); } return view; } @Override public boolean isChildSelectable(int i, int i2) { return false; } }
  There are many methods in this class but there are only two of them we need to focus on:
getChildrenCount: return the count of row of child item in a specific group. Here I’ve added two extra rows to the return method. The first row will be used for header and the second row will be used for footer.
getChildView: render the child list of each group. Here we will check the child position to inflate the appropriate layout to each row. The layout of header and footer will be inflated to the first and last of childPostion and the rest will show all items of the child list.
  Main activity and sample data for expandable list view
Once you are done with creating a custom adapter for your expandable list view, open the MainActivity class and copy the following code. In this activity I have also created sample data to display in the expandable list view.
public class MainActivity extends Activity { ExpandableListView elv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LayoutInflater inflater = getLayoutInflater(); elv = (ExpandableListView)findViewById(R.id.elv); elv.setOnGroupExpandListener(onGroupExpandListenser); MyExpandableAdapter adapter = new MyExpandableAdapter(this, getData()); elv.setAdapter(adapter); } ExpandableListView.OnGroupExpandListener onGroupExpandListenser = new ExpandableListView.OnGroupExpandListener() { int previousGroup =-1; @Override public void onGroupExpand(int groupPosition) { if(groupPosition!= previousGroup) elv.collapseGroup(previousGroup); previousGroup = groupPosition; } }; //Sample data for expandable list view. public List<ParentObject> getData() { List<ParentObject> parentObjects = new ArrayList<ParentObject>(); for (int i = 0; i<20; i++) { parentObjects.add(new ParentObject("Mother " +i, "Father " +i, "Header " + i, "Footer " +i, getChildren(i))); } return parentObjects; } private List<ChildObject> getChildren(int childCount) { List<ChildObject> childObjects = new ArrayList<ChildObject>(); for (int i =0; i<childCount; i++) { childObjects.add(new ChildObject("Child " + (i+1), 10 +i )); } return childObjects; } }
  Output
    Conclusion
I have just showed you how I added a header and footer to the ExpandableListView ChildView. Hope you find this post useful.
The completed project can be downloaded at GitHub HeaderAndFooterForExpandableListview
  If you like our articles, please follow and like our Facebook page where we regularly share interesting posts and check out our other blog articles.
RobustTechHouse is a leading tech company focusing on mobile app development in Singapore. If you are interested to have us work with you on your projects, you can contact us here.
How To Add Header Footer to ExpandableListview ChildView was originally published on RobustTechHouse - Mobile App Development Singapore
0 notes
jeeteshsurana · 6 years ago
Text
expandable list view in android
http://bit.ly/2PxK2g3
Expandable list view in android
Expandable  
extended view:- 
xml :-  __________________________________________________________________ <ExpandableListView             android:id="@+id/el_time_sheet"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:groupIndicator="@null"             android:childIndicator="@null"             android:layout_gravity="end" /> __________________________________________________________________ item_time_sheet_header.xml __________________________________________________________________ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout     xmlns:android="http://bit.ly/nIICcg"     xmlns:app="http://bit.ly/GEGVYd"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical"     android:layout_gravity="end">     <androidx.appcompat.widget.AppCompatTextView         android:id="@+id/txt_header"         style="@style/TextStyleTitle"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginTop="@dimen/dp_16"         android:layout_marginBottom="@dimen/dp_16"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> __________________________________________________________________ item_time_sheet.xml
__________________________________________________________________
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout         xmlns:app="http://bit.ly/GEGVYd"         xmlns:android="http://bit.ly/nIICcg"         android:layout_width="match_parent"         android:layout_height="wrap_content">     <androidx.appcompat.widget.AppCompatButton             android:id="@+id/btn_month"             style="@style/BtnStyleBlack"             android:textAllCaps="false"             android:layout_width="240dp"             android:padding="@dimen/dp_16"             android:hint="@string/btn_login"             android:layout_marginTop="@dimen/dp_16"             app:layout_constraintEnd_toEndOf="parent"             app:layout_constraintTop_toTopOf="parent"             app:layout_constraintStart_toStartOf="parent"             app:layout_constraintBottom_toBottomOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> __________________________________________________________________ Class.kt __________________________________________________________________ class TimeSheetFragment : BaseFragment() {     var listAdapter: ExpandableListAdapter? = null     var listDataHeader: ArrayList<String>? = null     var listDataChild: HashMap<String, List<String>>? = null     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {         return inflater.inflate(R.layout.fragment_time_sheet, container, false)     }     override fun onActivityCreated(savedInstanceState: Bundle?) {         super.onActivityCreated(savedInstanceState)         prepareListData()         listAdapter = ExpandableListAdapter(             context!!,             listDataHeader!!,             listDataChild!!,             object : ExpandableListAdapter.ItemClick {                 override fun buttonClick(groupPosition: Int, childPosition: Int) {                     Log.d(Constant.Tag, "Header-->" + listDataHeader!![groupPosition])                     Log.d(Constant.Tag, "Child-->" + listDataChild!![listDataHeader!![groupPosition]]!![childPosition])                 }             }         )         el_time_sheet.setChildIndicator(null)         el_time_sheet.setChildDivider(resources.getDrawable(R.color.white))         el_time_sheet.setAdapter(listAdapter)     }     /*    * Preparing the list data    */     private fun prepareListData() {         listDataHeader = ArrayList<String>()         listDataChild = HashMap<String, List<String>>()         for (i in 2019 downTo 2014) {             listDataHeader!!.add("" + i)         }         for ((count, i) in (2019 downTo 2014).withIndex()) {             val listChild = ArrayList<String>()             listChild.add(resources.getString(R.string.january))             listChild.add(resources.getString(R.string.february))             listChild.add(resources.getString(R.string.march))             listChild.add(resources.getString(R.string.april))             listChild.add(resources.getString(R.string.may))             listChild.add(resources.getString(R.string.june))             listChild.add(resources.getString(R.string.july))             listChild.add(resources.getString(R.string.august))             listChild.add(resources.getString(R.string.september))             listChild.add(resources.getString(R.string.october))             listChild.add(resources.getString(R.string.november))             listChild.add(resources.getString(R.string.december))             listDataChild!![listDataHeader!![count]] = listChild         }     } } ___________________________________________________________ ExpandableListAdapter.kt ___________________________________________________________ class ExpandableListAdapter(     private val _context: Context,     private val _listDataHeader: ArrayList<String>,     private val _listDataChild: HashMap<String, List<String>>,     private val mItemClick: ItemClick ) : BaseExpandableListAdapter() {     override fun getChild(groupPosition: Int, childPosititon: Int): Any {         return this._listDataChild[this._listDataHeader[groupPosition]]!![childPosititon]     }     override fun getChildId(groupPosition: Int, childPosition: Int): Long {         return childPosition.toLong()     }     override fun getChildView(         groupPosition: Int,         childPosition: Int,         isLastChild: Boolean,         convertView: View?,         parent: ViewGroup     ): View {         var convertView = convertView         val childText = getChild(groupPosition, childPosition) as String         if (convertView == null) {             val infalInflater = this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater             convertView = infalInflater.inflate(R.layout.item_time_sheet, null)         }         val txtListChild = convertView!!.findViewById<View>(R.id.btn_month) as AppCompatButton         txtListChild.text = childText         txtListChild.setOnClickListener {             mItemClick.buttonClick(groupPosition, childPosition)         }         return convertView     }     override fun getChildrenCount(groupPosition: Int): Int {         return this._listDataChild[this._listDataHeader[groupPosition]]!!.size     }     override fun getGroup(groupPosition: Int): Any {         return this._listDataHeader[groupPosition]     }     override fun getGroupCount(): Int {         return this._listDataHeader.size     }     override fun getGroupId(groupPosition: Int): Long {         return groupPosition.toLong()     }     override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View {         var convertView = convertView         val headerTitle = getGroup(groupPosition) as String         if (convertView == null) {             val infalInflater = this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater             convertView = infalInflater.inflate(R.layout.item_time_sheet_header, null)         }         val lblListHeader = convertView!!.findViewById<View>(R.id.txt_header) as TextView         lblListHeader.setTypeface(null, Typeface.BOLD)         lblListHeader.text = headerTitle         return convertView     }     override fun hasStableIds(): Boolean {         return false     }     override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {         return true     }     public interface ItemClick {         fun buttonClick(groupPosition: Int, childPosition: Int)     } }
___________________________________________________________
via Blogger http://bit.ly/2vpNaB9
0 notes
night-finance-site-blog · 8 years ago
Text
ポップアップウインドウ PopupWindow(this); mPopup.setWindowLayoutMode( ViewGroup.LayoutParams.WRAP_CONTENTE, ViewGroup.LayoutParams.WRAP_CONTENTE); mPopup.setContetnView(popupView); mPopup.showAsDropDown(btnPopup); mPopup.sidmiss();
リストポップアップウインドウ ListPopupwindow(this); ... mListPopup.setAdapter(adapter); ... mListPopup.setAnchorView(btnPopup); mListPopup.show();
ドラック&ドロップ iv_drop.setOnDragListener(new View.OnDraglistener() { public boolean onDrag(View v, DragEvent event) { ... ClipData clipData.getItemAt(i); Toast.maketext(getApplicationContenxt(0, ... switch (event.getAction()) { ... v.startDrag(clipData, new DragShadowBuilder(v), null 0);
src/DragView.java ... onDragEvent(DragEvent event) { ...
src/DropView.jaba ... public boolean onDragEvent(DragEvent event) { switch(event.getAction()) { case DragEvent.ACTION_DROP; ...
カレンダー表示 <CalendarView ... />
カレンダー日付変更イベント src/MainActivity.java... calView.setOnDateChangelistener(new OnDateChangeListener() { ... public void onSelecteDayChange(CalendarView view, int year, int month, int dayOfMonth) { ...
リストビュークリックイベント listView.setOnItemClickListener(new AdapterView.OnClickLidtener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
リストビュー表示位�� lv.setSelection(lv.getCount() - 1);
リストビュー先頭末尾 lv.addFotterView(mIvFooter); lv.removeFooterView(mIvFooter); return ture;
オーバースクロール setOverScrollMode(OVER_SCROLL_ALWAYS); @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int ScrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)
折り畳み可能リストビュー expandableView.setAdapter(adapter);
開閉リストビュークリックイベント expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @SuppressWarnings("unchecked") @Overridepublic boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
グリッドビュー gridView.setAdapter(adapter);
セルがクリック画像 gridView.setSelector(android.R.drawable.alert_light_frame);
セルクリックイベント gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
クロノメター <Chronometer ... />
クロノメター盛業 chronoMeter.setBase(SystemClock.elapsedRealtime()); chronoMeter.start(); chronoMeter.stop();
シークバー <SekBar ... />
シークバー最大値初期値 max Progress
シークバーイベント処理 @Overridepublic void onStartTrackingTouch(SeekBar seekBar) { setProgressBar IndeterminateVisibility(true); } @Overridepublic void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) { TExtView tvprogress = (TextView) findViewById(R.id.tvProgress); tvProgress.setText(Progress + "%..."); } @Overridepublic void onStopTrackingTouch(SeekBar seekBar) { setProgressBar IndeterminateVisiblity(false); } });
スピナー <Spinner ... />
スピナー表示項目 adapter.stDropDownviewResource(android.R.layout.simple_spinner_dropdown_item); spinnerAge.setAdapter(adapter); spinnerAge.setAdapter(adapter); spinnerAge.setPrompt("年齢の選択"); spinnerAge.setSelection(3);
スピナーのドロップダウンリスト spinnerAge.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Overridepublic void onItemSelected(Adapteriew<?> parent, View view, int position, long id) ... public void onNorthSelected(AdapterView<?> parent) {
スクロールビュー追加 <ScrollView ... </ScrollView>
スクロールバー表示位置 sv.setVerticalvarPosition(ScrollView.SCROLLBAR_POSITION_LEFT);
日付ピッカー <DatePicker ... />
日付ピッカーイベント処理 datePicker.init(2013, 6, 1, mLidtener); ... public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayMonth) {
時刻ピッカー <TimePicker ... />
時刻ピッカーイベント処理 public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
数値ピッカー <NumberPicker ... />
数値ピッカー最大値最小値 numberPicker.setMaxValue(50); numberPicker.setMinValue(10);
数値ピッカーイベント処理 numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangedListener() { @Overridepublic void onValueChange(NumberPicker picker, int oldVal, int newVal) {
アラートダイヤログ setMessage("アラートダイヤログ。\nAndroid SDKポケリ") setPositiveButton("OK", new DialogIntegerface.OnClickListener() { ... .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { ... public void onClick(DialogInterface dialog, int which) { ... .setNeutralButton("Neutral", new DialogInterface.OnClickListener() { ... return builder.create(); ... newFragment.show(getSupportFragmentManager(), "showAlertDialog"); }
日付ピッカーダイヤログ return new DatePickerDialog( getActivity(), DatePickerDialog,THEME_HOLD_DARK, this, 2013, 6, 1); } @Overridepublic void onDateSet(DatePicker view, int year, int monthYear, int dayOfMonth) { ...
時刻ピッカーダイヤログ return new TimePickerDialog( getActivity(), TimeActivity(), TimePickerDialog,THEME_HOLD_DARK, this, 12, 34, true); } ... public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
プログレスダイヤログ ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setTitle("処理中..."); dialog.setMessage("少々お待ちください...'); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
Notification表示 builder.setWhen(System.currentTimeMills()); ... notificationManager.notify(NOTIFY_SAMPLE, builder.build());
ステータスバー通知 icon level tickerText views
通知領域通知 autoCancel intent title text info icon
通知プロパティ defaults sound streamType argb onMs offMs pattern
消せない通知 notification.flags += Notification.FLAG_ONGOING_EVENT;
通知大きい画像 new NotificationCompat.BigPictureStyle(builder);
通知大きいテキスト bigTextNotification.bigText("文字が大きいです。"); bigTextNotification.setSummaryText("スタイルがBigTextStyle");
通知複数行 inboxStyleNotification.addLine("1"); inboxStyleNotification.addLine("2"); inboxStyleNotification.addLine("3"); inboxStyleNotification.setSummaryText("BigTextStyle");
通知UIカスタマイズ RemoteViews remoteView = new RemoteView(getPackageName(), R.layout.notification_layout); remoteView.setImageViewResource(R.id.ivIcon, R.drawable.ic_lancher); remoteView.setText(R.id.tvMessage, "..."); builder.setContent(remoteView);
通知ボタン追加 builder.addAction(android.R.drawable.stra_off, "Google", contentIntent1); ... builder.addAction(android.R.drawable.star_off, "...", contentIntent2); ... builder.addAction(android.R.drawable.star_off, "buildebox.net", contentIntent3);
スイッチ表示 <Switch ... />
スイッチイベント処理 ... sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { ... public void onChackedChanged(CompoundButton buttonView, boolean isChecked) { ...
メニューレイアウト res/menu/main.xml <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item .../> <item .../> <item .../> <groupPosition...> <item .../> <item .../> </group> </menu>
src/MainActivity.java... public boolean onCreateOptionMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); MenuItem item = menu.add(Menu.NONE, MENU_SAMPLE, 600, "..."); ...
メニュー選択 ... public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { ...
ポップアップメニュ ... popupMenu.getMenuInflateer().inflate(R.menu.popup_main, popupMenu.getMenu());
ポップアップメニュ処理 popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { ... public boolean onMenuItemClick(MenuItem item) { ...
コンテキストメニュ ... registerForContextMenu(lvFruits); ... public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { ...
コンテキストメニュ選択 onContextItemSelected(MenuItem item)
HOMEウィジット設定 <appwidget-provider ... </appwidget-provider>
<appwidget-provider... </appwidget-provider>
マニフェストHOMEウィジット <reciver ... <intent-filter> ... </intent-filter> <meta-data ... </reciver>
HOMEウィジット通知 ... onEnabled(Context context) { ... public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { ... public void onDeleted(Context context, int[] aqppWidgetIds) { ... public void onDisabled(Context contxt) { ... public void onReceive(Context context, Intent intent) { ...
HOMEウィジット更新 widgetManager.updateAppWidget(widget, removeViews);
HOME画面作成 ... <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" />
プリファレンス画面作成 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> ... </PreferenceScreen>
src/SettingPrefActivity.javapublic class SettingPrefActivity extends PreferenceActivity { ... addPreferencesFromResource(R.xml.setting_pref);
src/SettingPrefFragment.java public class SettingPrefFragment extends PreferenceFragment { ...
プレファレンス画面レイアウトカテゴリ <PreferenceCategory ... </PreferenceCategory> <PreferenceCategory ... </PreferenceActivity>
プリファレンスチェックボックス ... <CheckBoxPreference .../>
プリファレンスエディットテキスト <EditTextPreference .../>
プリファレンスリスト <ListPreference .../>
プリファレンス複数選択リスト <MultiSelectListPreference ... />
プリファレンススイッチ <SwitchPreference .../>
着信音通知音アラーム音 <RingtonePreference ... />
クリックイベント btn_click.setOnClickListener(new View.OnClidkListener() { ...
長押しイベント btn_longClick.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { ...
タッチイベント ... public boolean onTouchEvent(MotionEvent event) { ...
ViewPager画面切り替え <android.support.v4.view.pagerTabStrip ... />
src/MainActivity.java mViewPager.setAdapter(mPagerAdapter); ... public Fragment getItem(int position) { ... public int getCount() { ... getPageTitle(int position) ...
アプリーションアイコンナビゲーションドロワー res/layout/activity_main.xml res/layout/activity_main.xml... mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { ... public void onDrawerOpened(View drawerView) { ... public void onDrawerSlide(View drawView, float slideOffset) { ... public void onDrawerStateChange(int newState) { ... mDrawerLayout.setDrawerListener(mDrawerToggle); ... mDrawerToggle.syncstate(); ... public void onConfligurationChanged(Configration newConfig) { ... mDrawerLayout.openDrawer(Gravity.LEFT); ...
0 notes
android-arsenal · 9 years ago
Text
ExpandableRecyclerView
Custom RecyclerView#Adapter that implement features like ExpandableListView.
from The Android Arsenal http://ift.tt/2iWBk9R
0 notes
ysakaguchi · 11 years ago
Text
折りたたみのリストを作成
ExpandableListView
SimpleExpandableListAdapter
1 note · View note
shareandopen · 13 years ago
Text
如何控制ListView或ExpandableListView中間的分隔線(divider)
一般而言,正常的ListView或ExpandableListView在畫面上都會有一條預設的分隔線(Divider)來區分不同列的項目,就像下圖所示,都會看到一條偏灰色的分隔線
Tumblr media
而如果今天想要自訂分隔線的樣式的話像是不要顯示分隔線、要改變分隔線的高度、顏色.......等等等時,該怎麼做呢?android的layout描述檔提供很多相關的屬性可以設定,整理如下
和ListView相關的屬性如下
android:divider - 設定分隔線的顏色,如果要隱藏分隔線,此屬性要設定為"@null"
android:dividerHeight - 設定分隔線的高度,單位以dp為主
因為ExpandableListView是提供兩階層式的ListView,所以會有區分group, child,其相關的屬性如下
android:divider - 設定分隔線的顏色,如果要隱藏分隔線,此屬性要設定為"@null"
android:dividerHeight - 設定分隔線的高度,單位以dp為主
android:childDivider - 設定Child分隔線的顏色,如果隱藏分隔線,此屬性要設定為"@null"
在ExpandableListView使用divider和dividerHeight兩個屬性時要特別注意,因為這兩個屬性是繼承ListView而來,所以設定這兩個屬性是同步影響到group和child的分隔線樣式與高度。
以下為將android:divider="@null"的截圖結果
Tumblr media
0 notes
paolovecchio · 9 months ago
Text
0 notes
paolovecchio · 10 months ago
Text
0 notes
paolovecchio · 10 months ago
Text
0 notes
paolovecchio · 10 months ago
Text
0 notes
paolovecchio · 10 months ago
Text
0 notes
paolovecchio · 10 months ago
Text
0 notes
paolovecchio · 11 months ago
Text
1 note · View note
jeeteshsurana · 6 years ago
Link
Expandable list view in android
Expandable  
extended view:- 
xml :-  __________________________________________________________________ <ExpandableListView             android:id="@+id/el_time_sheet"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:groupIndicator="@null"             android:childIndicator="@null"             android:layout_gravity="end" /> __________________________________________________________________ item_time_sheet_header.xml __________________________________________________________________ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout     xmlns:android="http://bit.ly/nIICcg"     xmlns:app="http://bit.ly/GEGVYd"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical"     android:layout_gravity="end">     <androidx.appcompat.widget.AppCompatTextView         android:id="@+id/txt_header"         style="@style/TextStyleTitle"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginTop="@dimen/dp_16"         android:layout_marginBottom="@dimen/dp_16"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> __________________________________________________________________ item_time_sheet.xml
__________________________________________________________________
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout         xmlns:app="http://bit.ly/GEGVYd"         xmlns:android="http://bit.ly/nIICcg"         android:layout_width="match_parent"         android:layout_height="wrap_content">     <androidx.appcompat.widget.AppCompatButton             android:id="@+id/btn_month"             style="@style/BtnStyleBlack"             android:textAllCaps="false"             android:layout_width="240dp"             android:padding="@dimen/dp_16"             android:hint="@string/btn_login"             android:layout_marginTop="@dimen/dp_16"             app:layout_constraintEnd_toEndOf="parent"             app:layout_constraintTop_toTopOf="parent"             app:layout_constraintStart_toStartOf="parent"             app:layout_constraintBottom_toBottomOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> __________________________________________________________________ Class.kt __________________________________________________________________ class TimeSheetFragment : BaseFragment() {     var listAdapter: ExpandableListAdapter? = null     var listDataHeader: ArrayList<String>? = null     var listDataChild: HashMap<String, List<String>>? = null     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {         return inflater.inflate(R.layout.fragment_time_sheet, container, false)     }     override fun onActivityCreated(savedInstanceState: Bundle?) {         super.onActivityCreated(savedInstanceState)         prepareListData()         listAdapter = ExpandableListAdapter(             context!!,             listDataHeader!!,             listDataChild!!,             object : ExpandableListAdapter.ItemClick {                 override fun buttonClick(groupPosition: Int, childPosition: Int) {                     Log.d(Constant.Tag, "Header-->" + listDataHeader!![groupPosition])                     Log.d(Constant.Tag, "Child-->" + listDataChild!![listDataHeader!![groupPosition]]!![childPosition])                 }             }         )         el_time_sheet.setChildIndicator(null)         el_time_sheet.setChildDivider(resources.getDrawable(R.color.white))         el_time_sheet.setAdapter(listAdapter)     }     /*    * Preparing the list data    */     private fun prepareListData() {         listDataHeader = ArrayList<String>()         listDataChild = HashMap<String, List<String>>()         for (i in 2019 downTo 2014) {             listDataHeader!!.add("" + i)         }         for ((count, i) in (2019 downTo 2014).withIndex()) {             val listChild = ArrayList<String>()             listChild.add(resources.getString(R.string.january))             listChild.add(resources.getString(R.string.february))             listChild.add(resources.getString(R.string.march))             listChild.add(resources.getString(R.string.april))             listChild.add(resources.getString(R.string.may))             listChild.add(resources.getString(R.string.june))             listChild.add(resources.getString(R.string.july))             listChild.add(resources.getString(R.string.august))             listChild.add(resources.getString(R.string.september))             listChild.add(resources.getString(R.string.october))             listChild.add(resources.getString(R.string.november))             listChild.add(resources.getString(R.string.december))             listDataChild!![listDataHeader!![count]] = listChild         }     } } ___________________________________________________________ ExpandableListAdapter.kt ___________________________________________________________ class ExpandableListAdapter(     private val _context: Context,     private val _listDataHeader: ArrayList<String>,     private val _listDataChild: HashMap<String, List<String>>,     private val mItemClick: ItemClick ) : BaseExpandableListAdapter() {     override fun getChild(groupPosition: Int, childPosititon: Int): Any {         return this._listDataChild[this._listDataHeader[groupPosition]]!![childPosititon]     }     override fun getChildId(groupPosition: Int, childPosition: Int): Long {         return childPosition.toLong()     }     override fun getChildView(         groupPosition: Int,         childPosition: Int,         isLastChild: Boolean,         convertView: View?,         parent: ViewGroup     ): View {         var convertView = convertView         val childText = getChild(groupPosition, childPosition) as String         if (convertView == null) {             val infalInflater = this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater             convertView = infalInflater.inflate(R.layout.item_time_sheet, null)         }         val txtListChild = convertView!!.findViewById<View>(R.id.btn_month) as AppCompatButton         txtListChild.text = childText         txtListChild.setOnClickListener {             mItemClick.buttonClick(groupPosition, childPosition)         }         return convertView     }     override fun getChildrenCount(groupPosition: Int): Int {         return this._listDataChild[this._listDataHeader[groupPosition]]!!.size     }     override fun getGroup(groupPosition: Int): Any {         return this._listDataHeader[groupPosition]     }     override fun getGroupCount(): Int {         return this._listDataHeader.size     }     override fun getGroupId(groupPosition: Int): Long {         return groupPosition.toLong()     }     override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View {         var convertView = convertView         val headerTitle = getGroup(groupPosition) as String         if (convertView == null) {             val infalInflater = this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater             convertView = infalInflater.inflate(R.layout.item_time_sheet_header, null)         }         val lblListHeader = convertView!!.findViewById<View>(R.id.txt_header) as TextView         lblListHeader.setTypeface(null, Typeface.BOLD)         lblListHeader.text = headerTitle         return convertView     }     override fun hasStableIds(): Boolean {         return false     }     override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {         return true     }     public interface ItemClick {         fun buttonClick(groupPosition: Int, childPosition: Int)     } }
___________________________________________________________
0 notes