Android: Custom Dialog unwanted extra space - java

I'm having an issue with my custom dialog, it shows empty space at the right side when I set the width and hight to wrap_content. I don't want to use match_parent because the picture will be bigger and the layout will not be right when I do landscape.
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:layout_margin="2dp"
android:id="#+id/share_layout">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:id="#+id/rl4">
<ImageView
android:id="#+id/media_share_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/step_one" />
<Button
android:background="#drawable/red_button"
android:id="#+id/media_share_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dialog_button_share"
style="#style/button_text"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_alignLeft="#+id/media_share_img"
android:layout_below="#+id/media_share_img"
android:layout_alignRight="#+id/media_share_img" />
</RelativeLayout>
</RelativeLayout>
java:
View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_dialog_share, null);
dialog = new AlertDialog.Builder(getActivity()).setView(dialogView)
/* .setNeutralButton(getResources().getString(R.string.dialog_button_close), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
})*/.create();
/*
.setIcon(R.mipmap.ic_launcher).*/
dialog.setCanceledOnTouchOutside(true);
dialog.show();

Related

space between icon and title item in menu when call it in toolbar

I have the following menu:
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/menu_main_help"
android:title="#string/menu_help"
android:icon="#drawable/ic_information" />
<item
android:id="#+id/menu_main_about"
android:icon="#drawable/ic_information"
android:title="#string/menuabout_us" />
</menu>
I need to space between icon and border in menu to be clear show image please
enter image description here
I want show icon in overflow menu of Toolbar like that enter image description here
but i face a problem when I click to show options menu in tool bar the icon of item menu overlapping or hidden part from icon in border , I have the following toolbar:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/layoutbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_6sdp">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/_24sdp"
android:background="#color/colorPrimaryDark" />
</com.google.android.material.appbar.AppBarLayout>
This is toolbar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/teal_200"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<RelativeLayout
android:id="#+id/real_back"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerInParent="true"
android:layout_alignParentStart="true"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher_background">
<TextView
android:layout_width="18dp"
android:layout_height="14dp"
android:text="ABC"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
android:id="#+id/activity_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Birthday Card"
android:gravity="center"
android:textSize="14dp"
android:textStyle="bold"
android:layout_centerInParent="true"/>
<TextView
android:id="#+id/end"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="#drawable/ic_launcher_background"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"/>
<TextView
android:id="#+id/word"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="#drawable/ic_launcher_background"
android:layout_toLeftOf="#+id/end"
android:layout_marginEnd="10dp"/>
</RelativeLayout>
Add This is the layout where in use it
<?xml version="1.0" encoding="utf-8"?>
<include
android:id="#+id/topbar"
layout="#layout/toolbar"/>
<ListView
android:layout_width="100dp"
android:layout_height="200dp"
android:layout_below="#+id/topbar"
android:layout_alignParentEnd="true"
android:visibility="gone"
android:entries="#array/listarray"/>
Create this array in value/string.xml
<string-array name="listarray">
<item>ABCC</item>
<item>ABCD</item>
<item>EFDD</item>
</string-array>
Now what will do in activity is,,,
TextView textView = findViewById(R.id.listshow);
ListView listView= findViewById(R.id.listview);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(listView.getVisibility() == View.VISIBLE){
listView.setVisibility(View.GONE);
}
else {
listView.setVisibility(View.VISIBLE);
}
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long
id) {
if(position ==0 ){
Toast.makeText(MainActivity.this, "P1!", Toast.LENGTH_SHORT).show();
}
if(position ==1){
Toast.makeText(MainActivity.this, "p2", Toast.LENGTH_SHORT).show();
}
}
});
See Styling toolbar menu item title
Specifically, you can specify a custom layout for menu items using the actionLayout parameter as demonstrated:
android:actionLayout="#layout/custom_layout"

Android AlertDialogs are not showing buttons in specific acitivity

I want to show a basic Alert Dialog with Yes No options, but none of the methods seems to work. The dialog is shown but the YES NO buttons no I am working with API 26.
I am showing Alert Dialog in another activity with no problem (None of them are the main activity), even with custom layouts.
I am using many Alerts dialogs, but there is an example for go back confirmation.
#Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setMessage(getResources().getString(R.string.goBackAlert))
.setCancelable(false)
.setPositiveButton(_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ScanRouteActivity.super.onBackPressed();
}
})
.setNegativeButton(_no, null)
.show();
}
This function is working fine in another activity.
I've also tried something like this:
AlertDialog.Builder builder =new AlertDialog.Builder(getApplicationContext());
builder.setMessage(getResources().getString(R.string.goBackAlert));
builder.setCancelable(false);
builder.setPositiveButton(_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
QuarantineActivity.super.onBackPressed();
}
});
builder.setNegativeButton(_no, null);
AlertDialog dialog = builder.create();
dialog.show();
AND
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setMessage(getResources().getString(R.string.goBackAlert))
.setCancelable(false)
.setPositiveButton(_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
QuarantineActivity.super.onBackPressed();
}
})
.setNegativeButton(_no, null);
final AlertDialog ad = builder.create();
ad.show();
I've already try the followings AlertDialog imports:
import android.app.AlertDialog;
import androidx.appcompat.app.AlertDialog;
This are the XML for the Activities
In this activity is working fine:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorBackground"
tools:context=".ScanRouteActivity">
<TextView
android:id="#+id/txtVIdRoute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/TitleFont"
android:text=""/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/menuLabels"
android:layout_gravity="center"
android:id="#+id/txtVCurrentContent" />
<FrameLayout
android:id="#+id/frmScanContent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
HERE IS NOT WORKING
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorBackground"
tools:context=".QuarantineActivity">
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Select container type:"
android:textColor="#android:color/black"
/>
<Spinner
android:id="#+id/spinQType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/containerType_list"
/>
<Button
android:layout_marginStart="#dimen/default_margin"
android:layout_gravity="center"
android:gravity="center"
android:drawableStart="#drawable/add_photo"
android:id="#+id/btnAddPhoto"
android:enabled="false"
style="#style/circleBtnDark"/>
</TableRow>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frmQuarantine"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imgVPhoto"
android:maxWidth="150dp"
android:minWidth="150dp"
android:maxHeight="150dp"
android:minHeight="150dp"
android:layout_margin="#dimen/default_margin"
android:longClickable="true"
android:visibility="gone"
app:srcCompat = "#drawable/no_image"/>
</LinearLayout>
Okay,
Please try
<ImageView
...
android:src= "#drawable/no_image"/>
in your XML instead of
<ImageView
...
app:srcCompat = "#drawable/no_image"/>
GOODLUCK Bro
I had to implement a whole class and XML layout to manage AlertDialgs and after that I have not have issues with that, the bright side is that I had the opportunity to customize my AlertDialogs.

How to add a 'Click for more details' expandable field to AlertDialog in android

I have a AlertDialog that is shown when there is an error and it prints 'Error, could not be added/whatever", I also have the result of the exception that I'd like to parse but not shown to all users, only to those that want to click on 'details' and read the exception.
AlertDialog.Builder dialogo1 = new AlertDialog.Builder(activity);
dialogo1.setTitle("Error");
dialogo1.setMessage("Could not update movie: " + result);
dialogo1.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogo1, int id) {
activity.finish();
}
});
dialogo1.show();
There is my code, pretty simple, right? I haven't been able to find this answer anyway and I'm starting to think it is just not possible
what you want is a custom alert dialog.
so for that you will have to us a layout and define your dialog.Then initialize your listeners etc like it was a normal view that you are defining
dialog_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/header_logo"
android:layout_width="match_parent"
android:layout_height="64dp"
android:scaleType="center"
android:background="#FFFFBB33"
android:contentDescription="#string/app_name" />
<TextView
android:id="#+id/error"
andorid:text="Error Message"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/moreDetailsButton"
android:text="Click for more details"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/moreDetailsView"
android:text="Click for more details"
android:inputType="textPassword"
android:layout_width="match_parent"
android:visibility="gone";
android:layout_height="wrap_content"/>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/moreDetailsButton"
/>
</RelativeLayout>
and in your class
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_layout);
TextView error=(TextView)dialog.findViewById(R.id.error);
Button errorButton=(Button)dialog.findViewById(R.id.moreDetailsButton);
Button okButton=(Button)dialog.findViewById(R.id.ok);
//Do whatever you want with the rest of the dialog
// initialize all the onclick listeners a usual
errorButton.setOnClickListener(new View.onClickListener(){
#Override
public void onClick(View v){
TextView errorDetails=(TextView)dialog.findViewById(R.id.moreDetailsView);
errorDetails.setText(detailedErrorMessage) //add the details to this text view;
errorDetails.setVisibility(View.VISIBLE);
}
});
dialog.show();
Sorry if there are any syntactically errors if the ctrl+c,ctrl+v of this doesnt work.My IDE decided to misbehave today.
Follow this for details on a custom alert dialog.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/error"
android:text="Error Message"
android:layout_width="match_parent"
android:layout_height="37dp"
android:layout_toEndOf="#+id/moreDetailsView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/moreDetailsView"
android:text="No existen detalles para este tipo de error."
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="wrap_content" />
<Button
android:id="#+id/moreDetailsButton"
android:text="Click for more details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/moreDetailsView"
android:layout_below="#+id/error"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="139dp"
android:layout_height="wrap_content"
android:text="OK"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/moreDetailsView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>

Android List onListItemClick not working

I've got a new List of things that needs to be clicked but this one isn't working. onListItemClick is never called. I have another one in my app that has been working as expected and I can't figure out what the difference is. I've seen the people saying to change focusable but I've tried that a bunch of different ways with no effect. So here's some code.
Working:
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
// get the item that was clicked
v_ProjectInvestigatorSiteContact project = (v_ProjectInvestigatorSiteContact) this.getListAdapter().getItem(
position);
Intent myIntent = new Intent(this, Details.class);
myIntent.putExtra(res.getString(R.string.project), project);
startActivity(myIntent);
}// onListItemClick
Not Working:
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
// get the item that was clicked
final v_SitePeople vSitePeople = (v_SitePeople) this.getListAdapter().getItem(
position);
AlertDialog.Builder builder = new AlertDialog.Builder(Share.this);
builder.setTitle(res.getString(R.string.forgot_password_check_dialog_title))
.setMessage(res.getString(R.string.share_check_dialog_text))
.setPositiveButton(res.getString(R.string.send), new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
sendShareEmail(vSitePeople);
}
}).setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
// cancelled, so do nothing
}
});
AlertDialog msgBox = builder.create();
msgBox.show();
}// onListItemClick
Working XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<!-- dummy item to prevent edittext from gaining focus on activity start -->
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/title_background" >
<ImageView
android:id="#+id/logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_logo" >
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/logo"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="50dp"
android:paddingRight="60dp"
android:paddingTop="5dp"
android:text="#string/app_header"
android:textColor="#ffffffff"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/search_gradient" >
<ImageView
android:id="#+id/searchBoxIcon"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop"
android:src="#drawable/action_search" >
</ImageView>
<EditText
android:id="#+id/searchBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="#+id/searchBoxIcon"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_toRightOf="#+id/searchBoxIcon"
android:background="#drawable/search_box"
android:hint="#string/search_hint"
android:inputType="text"
android:maxLines="1"
android:minHeight="30sp"
android:paddingBottom="2dp"
android:paddingLeft="25sp"
android:paddingTop="2dp"
android:textColor="#ff000000" />
</RelativeLayout>
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/divider_gray"
android:cacheColorHint="#00000000"
android:divider="#color/divider_gray"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false" />
<TextView
android:id="#+id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="#string/loading"
android:textColor="#color/loading_gray"
android:textSize="20sp" />
</LinearLayout>
Not Working XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<!-- dummy item to prevent edittext from gaining focus on activity start -->
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/title_background" >
<ImageView
android:id="#+id/logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_logo" >
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/logo"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="50dp"
android:paddingRight="60dp"
android:paddingTop="5dp"
android:text="#string/share_header"
android:textColor="#ffffffff"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/divider_gray"
android:cacheColorHint="#00000000"
android:divider="#color/divider_gray"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false" />
<TextView
android:id="#+id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="#string/loading"
android:textColor="#color/loading_gray"
android:textSize="20sp" />
</LinearLayout>
Here is more on how the broken one works, just in case you want more code.
Not Working Row XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:baselineAligned="false"
android:orientation="vertical"
android:padding="6dp"
android:background="#ffffffff"
android:layout_margin="10dp" >
<TextView
android:id="#+id/toptext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/moreInfo"
android:gravity="center_vertical"
android:minHeight="20sp"
android:textColor="#ff000000"
android:textStyle="bold" />
</RelativeLayout>
Not Working View Adapter
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder = null;
if (convertView == null)
{
holder = new ViewHolder();
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.share_row, null);
convertView.setTag(holder);
}// if
else
{
holder = (ViewHolder) convertView.getTag();
}
v_SitePeople i = items.get(position);
if (i != null)
{
TextView topText = (TextView) convertView.findViewById(R.id.toptext);
topText.setGravity(Gravity.CENTER_VERTICAL);
topText.setMinHeight(40);
if (topText != null)
{
if (i.SitePerson != null)
{
if (i.PersonTitle != null)
{
topText.setText(String.format(i.SitePerson + ", " + i.PersonTitle));
}
else
{
topText.setText(i.SitePerson);
}
}// if has ProtocolNumber
else
{
if (i.Nickname != null)
{
topText.setText(i.Nickname);
}
}// if does not have ProtocolNumber
}// if
}// if
return convertView;
}// getView
Thank you so much for your help.
I figured it out. I never posted the relavant code, or I'm sure you guys would have found it for me.
My not working adapter had a isEnabled method copied from my functioning adapter that disabled items of type 0. But since my new list is all just one type everything was disabled.
Sorry for the trouble and thank you for your efforts.
You haven't shown where you initialise your list and adapter, but you need to make sure the onClickListner is set. Something like:
myListView.setOnItemClickListener(this);
edit: 'this' assuming initialization is done in the same class as the click listeners appear.
When you're using a ListView, you have mainly two layouts:
1)The layout where you have your listView
Example:
<?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:paddingTop="?attr/actionBarSize"
android:clickable="false"
>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#android:color/transparent"
android:clipToPadding="false"
android:paddingLeft="#dimen/list_left_padding"
android:paddingRight="#dimen/list_right_padding"
android:paddingTop="#dimen/list_separator"
android:dividerHeight="#dimen/list_separator"
android:paddingBottom="#dimen/list_separator" />
</RelativeLayout>
2)The layout which contains each item for your ListView.
Example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/white_responsive"
android:descendantFocusability="blocksDescendants"
>
<RelativeLayout
android:id="#+id/sampleItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:clipToPadding="false">
<com.devspark.robototextview.widget.RobotoTextView
android:id="#+id/textViewSample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingBottom="5dp"
android:text="Sample Text"
android:textSize="17sp"
app:typeface="roboto_regular" />
</RelativeLayout>
</RelativeLayout>
If you search on StackOverFlow about this problem, you will got the following instructions to solve it:
1) Add
android:descendantFocusability="blocksDescendants"
to the root of your layout
2) Add
android:clickable="false"
android:focusable="false"
To your item.
You can use these two options separately. The first one have helped me. But, you need to pay attention on where you need to put these attributes in your XML File. Put them in your ITEM layout, not in your ListView Layout. I'm saying this, because I was using that solution, but i was putting on the wrong xml. So, it just pay attention and it will work very well.

How can I access an ImageView inside of AlertDialog.Builder?

I have some code that creates a popup and assign it an XML layout that has two ImageView items in it.
popupWindow.setTitle("New note");
popupWindow.setMessage("choose the type of note to create");
View noteChoices = inflater.inflate(R.layout.addnotepopup, null);
popupWindow.setView(noteChoices);
popupWindow.setPositiveButton(null, null);
popupWindow.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//
}
});
popupWindow.show();
addnotepopup.xml has the two ImageView items
How can I add click listeners to those two items? When I try doing it the same way as any other button, findViewById() returns a null value
XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="2" >
<ImageView
android:id="#+id/recordnoteoption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:src="#drawable/medium_mic"
android:layout_weight="1" />
<ImageView
android:id="#+id/typenoteoption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:src="#drawable/medium_keyboard"
android:layout_weight="1" />
</LinearLayout>
Try this:
popupWindow.findViewById(R.id.yourId);
or if you want:
noteChoices.findViewById(R.id.yourId);

Categories

Resources