How to have two single choice list on alert dialog? - android

I need to implement two single choice list on an alert dialog. The two single choice items can be seen in the first picture. Once you clicked on the button , it will show a list of item(second picture). My question is how do I implement two single choice list item on an alert dialog? Thanks!
picture is adopted and a screenshots from VirtualGuitar+

You can create a layout with two spinners in horizontal linear layout.
Then make alert dialog with your layout xml like this
AlertDialog.Builder builderVal=new AlertDialog.Builder(mContext);
builderVal.setTitle("Title here") ;
View holder=View.inflate(mContext, R.layout.spinners, null);
builderVal.setView(holder);
Spinner spinner1 = (Spinner) holder.findViewById(R.id.spinner1);
//implement spinner logic
builderVal.setPositiveButton("Okay",null);
builderVal.show();
spinners.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner1"></Spinner>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner2"></Spinner>
</LinearLayout>

Related

How to create a bottomsheet view in android with listview showing datas stored in sqlite

I am creating an application in which i would like to know whether is it possible to show the list view inside a bottom sheet view .If so can anyone can tell me how i can do it because the examples which i have seen in bottom sheet shows only the share options.
Can anyone tell me is there any example relating this bottom sheets
Yes, You can implement Listview inside Bottom sheet View .
first you need to create xml layout for Bottom sheet, and defined Listview.
bottom_sheet_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center|top"
app:layout_behavior="#string/bottom_sheet_behavior"
>
<ListView
android:id="#+id/bottom_sheet_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
Defined BottomSheetDialog in your Activity.
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(TagSetupActivity.this);
View bottomSheetView = getLayoutInflater().inflate(R.layout.bootom_sheet_layout, null);
bottomSheetDialog.setContentView(bottomSheetViewVideo);
bottomSheetDialog.show();
ListView sheetListView= (ListView) bottomSheetView.findViewById(R.id.bottom_sheet_listview);
**and setadapter with data**
//**dataList == data fecth from sqlite.**
adapter=new BottomSheetListAdapter(this,dataList);
sheetListView.setAdapter(adapter);
Now, create BaseAdapter for showing data into List name with BottomSheetListAdapter
You can get an idea how to create a custom bottomsheet like a listview using below link
http://www.truiton.com/2016/07/android-bottom-sheet-example/

Customise context menu like pinterest menu

I've been looking for something like Pinterest menu whenever item in GridView is pressed. I know it's too broad question. But little strike on question will provide a correct way to achieve these.
Que:
How one can implement customise context menu like Contacts+ or Pinterest Context menu on GridView item?
Tried:
ArcMenu : But they are replacement of Slider Menu or Pop up Menu for overall Application. I want menu which can be created onFly for GridView Item.
Satellite Menu : Same as ArcMenu, replacement of Slider Menu or Pop up Menu for overall Application.
Please enlighten me to achieve behaviour like these.
I think instead of Context Menu you can use PopupWindow for your requirement.
//Custom popup view
View view= layoutInflater.inflate(R.layout.popupview, null);
PopupWindow popupWindow = new PopupWindow(
view,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
//Display popup window on clicking anything
//Displays pop up window near button with offsets 10 and -10
popupWindow.showAsDropDown(button, 10, -10);
For more info
http://developer.android.com/reference/android/widget/PopupWindow.html
http://android-er.blogspot.in/2012/03/example-of-using-popupwindow.html
Use quick action 3D view. It is the menu which is used in twitter application.
For source: https://github.com/lorensiuswlt/NewQuickAction3D
I'm using a modified version of ArcMenu (just small and mainly visual modifications) for something similar. And it's perfectly adaptable to gridview (i'm using it with StaggeredGridView onitemclick).
You only have to define it in the xml inside the gridview item with Visibility:gone and then in your gridview adapter or in the activity set it to visible when the item is touched or clicked...
don't know why you say it's for overall app, it can be used as an item element also.
You can check out this library which I created:
https://github.com/reyanshmishra/PinMenu
You can clone it and import it as a module to your app and do something like this:
In your XML layout:
<?xml version="1.0" encoding="utf-8"?>
<com.reyanshmishra.pinmenu.PinMenuHolder xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:pin_holder_draw_over_view="true"
app:pin_holder_overlay_color="#90ffffff">
<com.reyanshmishra.pinmenu.PinMenu
android:id="#+id/one"
android:layout_width="48dp"
android:layout_height="48dp"
android:elevation="5dp"
android:padding="5dp"
android:scaleType="centerInside"
android:src="#drawable/ic_close_black_24dp"
app:pin_background_color="#color/white"
app:pin_name="Cancel"
app:pin_selected_color="#BD081C" />
<com.reyanshmishra.pinmenu.PinMenu
android:id="#+id/three"
android:layout_width="48dp"
android:layout_height="48dp"
android:elevation="5dp"
android:padding="5dp"
android:scaleType="centerInside"
android:src="#drawable/share_variant"
app:pin_background_color="#color/white"
app:pin_name="Share"
app:pin_selected_color="#BD081C" />
<com.reyanshmishra.pinmenu.PinMenu
android:id="#+id/four"
android:layout_width="48dp"
android:layout_height="48dp"
android:elevation="5dp"
android:padding="5dp"
android:scaleType="centerInside"
android:src="#drawable/dots_horizontal"
app:pin_background_color="#color/white"
app:pin_name="More"
app:pin_selected_color="#BD081C" />
</com.reyanshmishra.pinmenu.PinMenuHolder>
Now in Java:
PinDialog mPinDialog = new PinDialog(this);
mPinDialog.setContentView(R.layout.layout_pin_menu);
mPinDialog.setPinSelectListener(new PinSelectListener() {
#Override
public void pinSelected(PinMenu pinMenu) {
Toast.makeText(mContext, "" + pinMenu.getPinName(), Toast.LENGTH_SHORT).show();
}
});
mPinDialog.addToRecyclerView(mRecyclerView);
It's still under development so it just supports recyclerview. For depth of the implementation, you can just skim through the classes of the library. I don't think I can put all the code here.
The result it something like this:

Custom AlertDialog

I'm created a custom AlertDialog, but
it have a default black border. How can I hide it?
My layout
props - match_parent,
style - #android:style/Theme.Translucent.NoTitleBar.Fullscreen
UPD
#Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus());
switch (id) {
case IDD_RESULT:
builder.setView(dialoglayout);
return builder.create();
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialog_layout_root"
style="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dialog_bg"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
The border is due to the fact that you might have set your custom layout (probably inflated) as the content view of the dialog.
I think AlertDialogs are composed by (at least) 3 layouts, one for the title, one for the content and one last for the buttons. So the little border you see might be the layout for the buttons.
I don't know how to make it disappear, anyway if you want custom dialogs without thoses borders, you can create a class that extends Activity, and use the #android:style/Theme.Dialog to make it look like a dialog. Then you can fully manage what your activity do/not shows.
What you are able to see is the default Style for any AlertDialog which normally varies from Device to Device. I tried a few times to change it, but I was not successful. So what I did is, I used the super Class Dialog and created my own AlertDialog.
Here is a link to my answer,
https://stackoverflow.com/a/11608468/603744
Since you are using your own layout, I believe that it will be of the same value.

Customize ListView in AlertDialog

Hey, I have a ListView that I want to be displayed into an AlertDialog, I have 2 problems:
1. The text is displayed in the left side, I want it to be in the center
2. To choose an item, you have to select exactly the text of the row.. How to make it possible to select the item even if selecting outside the text in the same row?
You can see in the picture that the orange highlight is on the text itself only rather than the whole row..:
Code:
LinearLayout layout = new LinearLayout(mContext);
ListView lv = new ListView(mContext);
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, BooksOptions));
Builder alert;
alert = new AlertDialog.Builder(this);
layout.addView(lv);
alert.setView(layout);
You're utilizing the standard Android list item layout, android.R.layout.simple_list_item_1. Instead, create your own item layout based on that layout and set the properties appropriately.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
/>
Note that you're also not setting layout properties on the ListView itself. Ensure that you specify it to have it match_parent for width as well in your layout.

Custom Listview Adapter, adding a static footer, and understanding R.id.list

There is something I'm just not getting, and I'm looking for assistance in understanding what is happening here.
I have a custom list adapter (that just extends BaseAdapter) that I have successfully been using to generate and display a list. Now I want to add a static footer to the bottom of my list. After looking at a number of resources (specifically this one) I've come to realize that my reluctance of using XML has to come to an end, and set up the following xml layout in a file called devices_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:id="#+id/bottom_control_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ToggleButton android:id="#+id/bottom_control_toggle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textOff="Filter Favourites OFF"
android:textOn="Filter Favourites ON"/>
</LinearLayout>
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_above="#id/bottom_control_bar">
</ListView>
<TextView android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/main_empty_list"
android:layout_above="#id/bottom_control_bar"/>
</RelativeLayout>
After some adjustments to the activity that holds the list, I ran the code. I see my footer, (and also the tab widget which is parent to everything), but the area where the list goes is empty.
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.devices_list);
db = new DbManager(this);
db.open();
AllCur = db.fetchAllDevices();
startManagingCursor(AllCur);
list = new DeviceListAdapter(this, AllCur); //make my custom list adapter
setListAdapter(list);
}
Is there some way to link up the ListView widget declared in my xml with my DeviceListAdapter? It's pretty clear to me now that I'm not entirely sure about how this is all working. Any help in clarification would be much appreciated.
You have both the ListView and the TextView set to android:layout_above="#id/bottom_control_bar", which means the TextView will overlap the ListView. And, you have said that your ListView height is 0dip, which will make for an extremely short list.
I would define the ListView as being above the TextView and anchored to the top of the screen (android:layout_alignParentTop="true").
Is there some way to link up the
ListView widget declared in my xml
with my DeviceListAdapter?
You already are, by calling setListAdapter().

Categories

Resources