If else statement of popup when click different image button in android - java

I am face some problem about the if else statement of the popup window.i want to set when i click different image button and then will pop up different image, but now after i code and test the pop up is no function...
this is my java code
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.macarons, container, false);
ImageButton ma1 = (ImageButton) view.findViewById(R.id.ma1);
ImageButton ma2 = (ImageButton) view.findViewById(R.id.ma2);
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
final int width = size.x;
final int height = size.y;
positionPopup = (RelativeLayout) view.findViewById(R.id.popup_position);
if (view.equals(ma1)) {
ma1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup, null);
ImageView img1 = (ImageView) customView.findViewById(R.id.popup_img);
img1.setImageResource(R.drawable.ma_bananacho_popup);
myPopUp = new PopupWindow(customView);
myPopUp.setWidth(width - 50);
myPopUp.setHeight(height - 50);
myPopUp.setOutsideTouchable(true);
myPopUp.setFocusable(true);
myPopUp.showAtLocation(positionPopup, Gravity.CENTER, 0, 0);
}
});
}
else if (view.equals(ma2)) {
ma2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup, null);
ImageView img2 = (ImageView) customView.findViewById(R.id.popup_img);
img2.setImageResource(R.drawable.chocolate);
myPopUp = new PopupWindow(customView);
myPopUp.setWidth(width - 50);
myPopUp.setHeight(height - 50);
myPopUp.setOutsideTouchable(true);
myPopUp.setFocusable(true);
myPopUp.showAtLocation(positionPopup, Gravity.CENTER, 0, 0);
}
});
}
return view;
}
this is my popup xml
<?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="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/popup_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
</RelativeLayout>
and this is fragment xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:layout_alignParentTop="true"
tools:ignore="ContentDescription">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF"
android:id="#+id/popup_position">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp">
<ImageButton
android:layout_width="0dp"
android:layout_height="190dp"
android:layout_columnWeight="1"
android:background="#drawable/ma_bananacho"
android:gravity="center"
android:layout_gravity="fill_horizontal"
android:id="#+id/ma1"/>
<ImageButton
android:id="#+id/ma2"
android:layout_width="0dp"
android:layout_height="190dp"
android:layout_columnWeight="1"
android:layout_gravity="fill_horizontal"
android:background="#drawable/ma_blueberry"
android:gravity="center" />
<ImageButton
android:layout_width="0dp"
android:layout_height="190dp"
android:layout_columnWeight="1"
android:background="#drawable/ma_chomint"
android:gravity="center"
android:layout_gravity="fill_horizontal" />
<ImageButton
android:layout_width="0dp"
android:layout_height="190dp"
android:layout_columnWeight="1"
android:background="#drawable/ma_coffee"
android:gravity="center"
android:layout_gravity="fill_horizontal" />
<ImageButton
android:layout_width="0dp"
android:layout_height="190dp"
android:layout_columnWeight="1"
android:background="#drawable/ma_greentea"
android:gravity="center"
android:layout_gravity="fill_horizontal" />
<ImageButton
android:layout_width="0dp"
android:layout_height="190dp"
android:layout_columnWeight="1"
android:background="#drawable/ma_strawcho"
android:gravity="center"
android:layout_gravity="fill_horizontal" />
</GridLayout>
</RelativeLayout>
</ScrollView>

View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup, null);
ImageView img1 = (ImageView) customView.findViewById(R.id.popup_img);
if (v.getId() == R.id.ma1) {
img1.setImageResource(R.drawable.ma_bananacho_popup);
} else if (v.getId() == R.id.ma2) {
img1.setImageResource(R.drawable.chocolate);
}
myPopUp = new PopupWindow(customView);
myPopUp.setWidth(width - 50);
myPopUp.setHeight(height - 50);
myPopUp.setOutsideTouchable(true);
myPopUp.setFocusable(true);
myPopUp.showAtLocation(positionPopup, Gravity.CENTER, 0, 0);
}
};
ma1.setOnClickListener(clickListener);
ma2.setOnClickListener(clickListener);
Create a common clickListener set it to the 2 image views ma1, ma2
Change the image resource of popup by comparing viewIds as below

in java any overide method will not work in inside if condition because overide method should come directly inside class . so when you r using any overide method you have to put in under the class or direct in class . hare you r using anonymous
class so you have to put if else inside overide onclick method .for exa.
View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
if(condition){
//for if condition is true
}else{
//for if condition is false
}
}
};

Related

Dialog width and height issue

i use custom dialog but in mobile device and in tab view but design is change when i check on tab
i want same same dialog in all device.
See my below code.
private void startDialog() {
final Dialog dialog = new Dialog(activity);
int width = (int)(getResources().getDisplayMetrics().widthPixels*0.70);
int height = (int)(getResources().getDisplayMetrics().heightPixels*0.65);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setContentView(R.layout.checkout_alert_dialog);
dialog.show();
dialog.getWindow().setLayout(width, height);
btn_cancle = dialog.findViewById(R.id.btn_cancle);
btn_cancle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(activity, "Cancel coming soon", Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
btn_continue = dialog.findViewById(R.id.btn_continue);
btn_continue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(activity, " Ok coming soon", Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
}
Below is Dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/iv_pointBox"
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:src="#drawable/ic_chekout_popup"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/_30sdp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/normal_input_text_size"
android:text="You've chosen to redeem 865 Points and pay 44.44 AED. The Payment process might take Some times, please do not hit the back button or close the app. Would you like to continue. "
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginRight="#dimen/_20sdp"
android:layout_below="#+id/iv_pointBox"
android:layout_marginTop="#dimen/_15sdp"
/>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/_1sdp"
android:background="#color/view_color"
android:layout_above="#+id/linerbutton"
/>
<LinearLayout
android:id="#+id/linerbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/btn_cancle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/lable_cancel"
android:textColor="#color/black"
android:textSize="#dimen/normal_input_text_size"
android:textStyle="bold"
android:background="#null"
android:gravity="center"
android:layout_weight="1"
/>
<View
android:layout_width="#dimen/_1sdp"
android:layout_height="#dimen/_45sdp"
android:background="#color/view_color"
/>
<Button
android:id="#+id/btn_continue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/lable_continue"
android:textColor="#color/black"
android:textSize="#dimen/normal_input_text_size"
android:textStyle="bold"
android:background="#null"
android:layout_weight="1"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I mention 2 screenshot of my device :
Mobile Device Screen shot:
Tab Screenshot :
See in screenshot dialog was change. So how to i fix it
Thanks in Advance :
Just look at your layout.xml Your layout height and width is match_parent then it's create a spaces.
Just replace your xml with my xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="#dimen/_250sdp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:id="#+id/iv_pointBox"
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:src="#drawable/ic_chekout_popup"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/_30sdp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/normal_input_text_size"
android:text="You've chosen to redeem 865 Points and pay 44.44 AED. The Payment process might take Some times, please do not hit the back button or close the app. Would you like to continue. "
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/_20sdp"
android:layout_marginRight="#dimen/_20sdp"
android:layout_below="#+id/iv_pointBox"
android:layout_marginTop="#dimen/_15sdp"
/>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/_1sdp"
android:background="#color/view_color"
android:layout_marginTop="#dimen/_50sdp"
/>
<LinearLayout
android:id="#+id/linerbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/btn_cancle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/lable_cancel"
android:textColor="#color/black"
android:textSize="#dimen/normal_input_text_size"
android:textStyle="bold"
android:background="#null"
android:gravity="center"
android:layout_weight="1"
/>
<View
android:layout_width="#dimen/_1sdp"
android:layout_height="#dimen/_45sdp"
android:background="#color/view_color"
/>
<Button
android:id="#+id/btn_continue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/lable_continue"
android:textColor="#color/black"
android:textSize="#dimen/normal_input_text_size"
android:textStyle="bold"
android:background="#null"
android:layout_weight="1"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And remove below three lines in java file No need to change height and width at run time:
int width = (int)(getResources().getDisplayMetrics().widthPixels*0.70);
int height = (int)(getResources().getDisplayMetrics().heightPixels*0.65);
dialog.getWindow().setLayout(width, height);
try custom layout
custom.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dp" />
<TextView
android:id="#+id/textDialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_toRightOf="#+id/imageDialog"/>
<Button
android:id="#+id/declineButton"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Submit "
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/textDialog"
android:layout_toRightOf="#+id/imageDialog"
/>
</RelativeLayout>
in java file
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title");
to open dialog use
dialog.show();
to dismiss dialog use
dialog.dismiss();
Personally, I prefer to create DialogFragment and set width and height like that:
#Override
public void onResume() {
super.onResume();
Window window = getDialog().getWindow();
int width = getArguments().getInt(BUNDLE_KEY_WIDTH);
int height = getArguments().getInt(BUNDLE_KEY_HEIGHT);
window.setLayout(width, height);
}
Replace the
myAlertDialog.show();
by
alertDialog.show();
and then
alertDialog.getWindow().setLayout(width,height);
it will work perfectly
complete code:
private void startDialog() {
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.setTitle("title");
myAlertDialog.setMessage("use this");
AlertDialog alertDialog = myAlertDialog.create();
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = (int) ((int)displaymetrics.widthPixels * 0.9);
int height = (int) ((int)displaymetrics.heightPixels * 0.7);
myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent pictureActionIntent = null;
pictureActionIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pictureActionIntent, GALLERY_PICTURE);
}
});
myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 15);
}
});
alertDialog.show();
alertDialog.getWindow().setLayout(width,height);
}
if still not working then you can use like this:
class DialogView extends DialogFragment {
Context context;
public static DialogView newInstance() {
DialogView f = new DialogView();
return f;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme);
context = this.getActivity();
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(getActivity(), getTheme()) {
#Override
public void onBackPressed() {
//do your stuff
}
};
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.button_layout_view, container, false);
setCancelable(false);
// RelativeLayout closeBtn = (RelativeLayout) view.findViewById(R.id.bottom_separator); get button ids like this- gallery camera etc and you can use click listener on that
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = (int) (metrics.widthPixels * 0.90);
int height = (int) (metrics.heightPixels * 0.95);
this.getDialog().getWindow().setLayout(width, height);
return view;
}
public static DisplayMetrics getDeviceMetrics(Context context) {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
display.getMetrics(metrics);
return metrics;
}
}
create xml for that with two button and title
button_layout_view
then call like this :
android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
DialogFragment newFragment = DialogView.newInstance();
newFragment.show(ft, "");
Your dialog's width and height is fine in both devices (you are setting them in your startDialog() method).
If you want the ImageView to be smaller in tablet devices, so the proportions are the same in both mobile and tablets, you should use a different dimens file for them:
First, define a dimen for your image:
Inside dimens.xml
<dimen name="dialog_image_size">XXXdp</dimen>
Then, define the same dimen inside /res/values-sw720dp/dimens.xml for 10'' tablets and inside /res/values-sw600dp/dimens.xml for 7'' tablets, and set a smaller dp for them.
Now, when you are on a tablet, a different size will be loaded, so you can use a smaller one to keep the same proportions than in mobile.

Screen turns background colour when clicking on EditText inside ExpandableListView

I've been struggling to figure out this weird bug for a day and a half. Whenever I click on an EditText that is a child of an ExpandableListView, the screen gets obscured such that the user is unable to see what is being typed, as shown in the gif below: \n
https://giant.gfycat.com/GenuineUnluckyHyrax.mp4
I started digging into the Hierarchy View to see what could be doing this, here is a screenshot of it:
https://i.imgur.com/B4kkHv7.png
To me it looks like the Toolbar up top is extending downwards to cover the screen, which is odd because it doesnt do that on other activities that contain EditText widgets. I've checked that parent views are using "wrap_content" for height instead of "match_parent" as well, except for my DrawerLayout which must match_parent. Below is the layout code for the activity:
<!-- This DrawerLayout has two children at the root -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rlcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<!--SideBar views -->
<RelativeLayout
android:layout_width="350dp"
android:layout_height="match_parent"
android:background="#color/sidebarColor">
<ExpandableListView
android:id="#+id/qwedit_sidebar_elv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indicatorLeft="?
android:attr/expandableListPreferredItemIndicatorLeft"
android:divider="#color/colorPrimary"
android:dividerHeight="0.5dp">
</ExpandableListView>
</RelativeLayout>
<!--MainView views -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ExpandableListView
android:id="#+id/qwedit_main_elv"
android:layout_width="930dp"
android:layout_height="wrap_content"
android:indicatorLeft="?
android:attr/expandableListPreferredItemIndicatorLeft"
android:divider="#color/colorPrimary"
android:dividerHeight="0.5dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="25dp">
</ExpandableListView>
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="#+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
android:layout_marginTop="25dp"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
Here is the EVL's group layout:
<?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">
<TextView
android:id="#+id/qwedit_sidebar_elv_parent_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:padding="3dp"
android:layout_marginLeft="40dp"
android:gravity="center"
android:textSize="20sp"
android:text="Category"/>
<ImageView
android:id="#+id/qwedit_elv_parent_status"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="35dp"
android:src="#drawable/ic_warning"/>
<TextView
android:id="#+id/qwedit_elv_parent_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_gravity="left"
android:gravity="right"
android:textColor="#color/colorPrimary"
android:textSize="20sp"
android:text="Score"/>
</LinearLayout>
and the item layout
<?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">
<LinearLayout
android:id="#+id/qwedit_elv_item_score_container"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/qwedit_main_badView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="#color/badScore">
<TextView
android:id="#+id/qwedit_main_badTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#color/white"
android:textSize="20sp"
android:text="Bad"/>
</LinearLayout>
<LinearLayout
android:id="#+id/qwedit_main_mediocreView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="#color/mediocreScore">
<TextView
android:id="#+id/qwedit_main_mediumTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#color/white"
android:textSize="20sp"
android:text="Mediocre"/>
</LinearLayout>
<LinearLayout
android:id="#+id/qwedit_main_goodView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="#color/goodScore">
<TextView
android:id="#+id/qwedit_main_goodTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#color/white"
android:textSize="20sp"
android:text="Good"/>
</LinearLayout>
<LinearLayout
android:id="#+id/qwedit_main_wcView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="#color/worldclassScore">
<TextView
android:id="#+id/qwedit_main_worldclassTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#color/white"
android:textSize="20sp"
android:text="World Class"/>
</LinearLayout>
</LinearLayout>
<EditText
android:layout_width="930dp"
android:layout_height="wrap_content"
android:layout_below="#+id/qwedit_elv_item_score_container"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Comments"/>
</RelativeLayout>
I'm assuming that this is all due to the layouts, but here is the CustomExpandableListAdapter that I wrote for it just in case the answer lies in how the views are being inflated:
/**
* Created by Tadhg on 9/8/2017.
*/
public class QwEditMainCustomExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> expandableListTitle;
private HashMap<String, List<String>> expandableListDetail;
//Values inits
private int categoryScore;
private int subCategoryScore;
private boolean completedCategory;
private boolean completedSubCategory;
// ChildView views
private View badScoreView;
private View mediocreScoreView;
private View goodScoreView;
private View worldclassScoreView;
TextView badScoreTextView;
TextView mediocreScoreTextView;
TextView goodScoreTextView;
TextView worldClassScoreTextView;
EditText questionCommentEditText;
public QwEditMainCustomExpandableListAdapter(Context context, List<String> expandableListTitle,
HashMap<String, List<String>> expandableListDetail) {
this.context = context;
this.expandableListTitle = expandableListTitle;
this.expandableListDetail = expandableListDetail;
}
#Override
public Object getChild(int listPosition, int expandedListPosition) {
return this.expandableListDetail
.get(this.expandableListTitle.get(listPosition))
.get(expandedListPosition);
}
#Override
public long getChildId(int listPosition, int expandedListPosition) {
return expandedListPosition;
}
#Override
public View getChildView(int listPosition, final int expandedListPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
final String expandedListText = (String) getChild(listPosition, expandedListPosition);
if(convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.qwedit_main_elv_item, null);
}
// ChildView views
badScoreView = convertView.findViewById(R.id.qwedit_main_badView);
mediocreScoreView = convertView.findViewById(R.id.qwedit_main_mediocreView);
goodScoreView = convertView.findViewById(R.id.qwedit_main_goodView);
worldclassScoreView = convertView.findViewById(R.id.qwedit_main_wcView);
badScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_badTextView);
mediocreScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_mediumTextView);
goodScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_goodTextView);
worldClassScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_worldclassTextView);
// TODO: TextView score subcategory setters
badScoreView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 1;
badScoreView.setBackgroundColor(Color.parseColor("#eca9a7"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e"));
goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8"));
}
});
mediocreScoreView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 2;
badScoreView.setBackgroundColor(Color.parseColor("#d9534f"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f7d6a6"));
goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8"));
}
});
goodScoreView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 3;
badScoreView.setBackgroundColor(Color.parseColor("#d9534f"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e"));
goodScoreView.setBackgroundColor(Color.parseColor("#addbad"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8"));
}
});
worldclassScoreView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 4;
badScoreView.setBackgroundColor(Color.parseColor("#d9534f"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e"));
goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#80baeb"));
}
});
/**
* Use variables categoryScore and subCategoryScore to update scores
*/
return convertView;
}
#Override
public int getChildrenCount(int listPosition) {
return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)).size();
}
#Override
public Object getGroup(int listPosition) {
return this.expandableListTitle.get(listPosition);
}
#Override
public int getGroupCount() {
return this.expandableListTitle.size();
}
#Override
public long getGroupId(int listPosition) {
return listPosition;
}
#Override
public View getGroupView(int listPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String listTitle = (String) getGroup(listPosition);
if(convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.qwedit_main_elv_group, null);
}
TextView listTitleTextView = (TextView) convertView
.findViewById(R.id.qwedit_main_elv_parent_title);
listTitleTextView.setText(listTitle);
return convertView;
}
#Override
public boolean hasStableIds() { return false; }
#Override
public boolean isChildSelectable(int listPosition, int expandedListPosition) { return true; }
}
Any points or tips would be great. I think that this may be due to the number of views in my hierarchy (or at least a subissue of it), but I'm not sure and am relatively new to Android Development.
Thanks!
I solved the issue, simply adding android:windowSoftInputMode="adjustNothing|stateHidden" caused the ActionBar to not expand to 996px when the EditText gained focus

How to setimageresource of popup imageview's image from activityA's button - Android

Currently I have a activity that has a lot of buttons and each button pops up a popup that is used from this site
each button has its own image to view, i wanted to change the image rather than creating individual popup.
ActivityA
Button backbtn;
public ImageView image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hiraganaactivity);
final Button btnOpenPopup = (Button)findViewById(R.id.abutton);
btnOpenPopup.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button) popupView.findViewById(R.id.close);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(btnOpenPopup, 30, -250);
}
});
final Button ibutton = (Button)findViewById(R.id.ibutton);
ibutton.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
image = (ImageView) findViewById(R.id.imageview);
image.setImageResource(R.drawable.hiraflash_i);
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.close);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAsDropDown(btnOpenPopup, 30, -250);
}});
backbtn = (Button) findViewById(R.id.backhira);
backbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(HiraganaActivity.this, Study_Menu.class));
finish();
}
});
}
When abutton is clicked, the popup shows normally with the default set image.
However when ibutton is clicked, the application crashes.
Edit:
HiraganaActivity.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".HiraganaActivity"
tools:showIn="#layout/activity_hiraganaactivity"
android:background="#drawable/hiraganabg"
>
<Button
style="?android:attr/buttonStyleSmall"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop = "#drawable/adraw"
android:id="#+id/abutton"
android:layout_marginTop="100dp"
android:layout_marginLeft="9dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20sp"
android:text="a"
android:typeface="normal" />
<Button
style="?android:attr/buttonStyleSmall"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop = "#drawable/idraw"
android:text="i"
android:id="#+id/ibutton"
android:layout_alignTop="#+id/abutton"
android:layout_toRightOf="#+id/abutton"
android:layout_toEndOf="#+id/abutton"
android:textSize="20sp"
android:typeface="normal"
android:layout_marginLeft="1dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:id="#+id/backhira"
android:textStyle="bold|italic"
android:textSize="15sp"
android:layout_marginBottom="26dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="false"
android:layout_centerHorizontal="true"
android:backgroundTint="#b9f600"
android:textColor="#0414a3" />
And Popup.xml
<?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="vertical"
android:background="#00546e">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="2dp"
android:background="#929292">
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aflashhira"
android:id="#+id/imageview" />
<Button
android:id="#+id/close"
android:layout_marginTop="10dp"
android:layout_marginLeft="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close" />
</LinearLayout>
</LinearLayout>
From Log:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.afropoker.kanaapp.HiraganaActivity$2.onClick(HiraganaActivity.java:56)
After you inflate your popup view
View popupView = layoutInflater.inflate(R.layout.popup, null);
Get the imageview using -
ImageView img = (ImageView)popupView.findViewById(R.id.img);// whatever is the id of your ImageView in your popup layout
img.setBackgroundResource(R.id.background_res); //any resource id which you want to set as a background
Using above mechanism you can change the image background any time you want

Images does not scroll in ViewPager in Android

I'm implementing View-pager in List-view as row item .When run the application my images is not scrolling one by one in view pager. What is the wrong in my code. Can someone suggest me how to make it work or scrolling smoothly images in view pager.
Here is my code
public class Demo_Display extends Activity {
private String str[] = {"weklfjo","??2","??3"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView)findViewById(R.id.listview);
MyListAdapter adapter = new MyListAdapter(this,R.layout.row,str);
listView.setAdapter(adapter);
}
class MyListAdapter extends ArrayAdapter<String> {
private LayoutInflater inflater = null;
private static final float BUTTON_WIDTH_DP = 70f;
private int margin;
public MyListAdapter(Context context, int resource,String[] items) {
super(context, resource,items);
inflater = LayoutInflater.from(context);
float density = getContext().getResources().getDisplayMetrics().density;
int buttonWidthPX = (int) (BUTTON_WIDTH_DP * density + 0.5f);
WindowManager wm = (WindowManager)getContext().getSystemService(getContext().WINDOW_SERVICE);
Display dp = wm.getDefaultDisplay();
margin = dp.getWidth() - buttonWidthPX;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = inflater.inflate(R.layout.row,null);
}
ViewPager viewPager = (ViewPager)convertView.findViewById(R.id.Image_ViewPagers);
viewPager.setPageMargin(-margin);
// MyPagerAdapter adapter = new MyPagerAdapter(getContext(),getItem(position));
MyPagerAdapter adapter = new MyPagerAdapter(getContext());
viewPager.setAdapter(adapter);
return convertView;
}
}
class MyPagerAdapter extends PagerAdapter {
Context mContent;
LayoutInflater mLayoutInflater;
private int[] GalImages = new int[] {
R.drawable.flower1,
R.drawable.flower1
};
public MyPagerAdapter(Context context) {
super();
mContent = context;
mLayoutInflater = (LayoutInflater) mContent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public Object instantiateItem(ViewGroup container, int position)
{
ImageView imageView = new ImageView(mContent);
int padding = mContent.getResources().getDimensionPixelSize(R.dimen.abc_button_padding_horizontal_material);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
#Override
public int getCount() {
// return PAGE_NUM;
return GalImages.length;
}
#Override
public boolean isViewFromObject(View view, Object obj) {
//return view.equals(obj);
return view == ((ImageView) obj);
}
}
}
Here is my XML file
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txt_InitialLetter"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/circle_shape"
android:gravity="center"
android:paddingBottom="5sp"
android:text="jsdygf" />
<TextView
android:id="#+id/txt_Desc"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal|left"
android:paddingLeft="5sp"
android:text="sdkjhfeorygdshgvfsjd" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:orientation="horizontal"
android:paddingLeft="5sp" >
<android.support.v4.view.ViewPager
android:id="#+id/Image_ViewPagers"
android:layout_width="fill_parent"
android:layout_height="190dp"
android:background="#android:color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="4dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/reply_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/retweet_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/star" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/camera_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/recorder_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/follow_up" />
</LinearLayout>
</LinearLayout>
and List View 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:orientation="vertical" >
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>

setOnClickListener not firing with custom adapter and custom ListView

I've been spending a few hours on a problem and I still can't figure it out. The setOnClickListener in HotelOverviewFragment is not firing when I click an item in my ListView. However, the setOnClickListener does work from my custom adapter (NowArrayAdapter).
My question is: why the setOnClickListener not working in HotelOverviewFragment (Class where the ListView is shown)?
Here's a list of what I've tried:
Setting android:focusable="false", android:focusableInTouchMode="false", android:descendantFocusability="blocksDescendants" in the hotel_row_layout.xml and fragment_hotel_overview.xml.
Setting android:clickable on true and false. Both didn't work.
Changing from BaseAdapter implementation to arrayAdapter.
I tried different listeners in HotelOverviewFragment: setOnClickListener, setOnItemClickListener, setOnItemSelectedListener and setOnTouchListener. Unfortunately, none of those worked for me.
Here's my code:
Custom adapter
public class NowArrayAdapter extends ArrayAdapter<String> {
private Context context;
private ArrayList<String> values;
private Typeface typeface;
private static Hashtable fontCache = new Hashtable();
private LayoutInflater inflater;
private TextView item;
public NowArrayAdapter(Context context, ArrayList<String> commandsList) {
super(context, R.layout.hotel_row_layout, commandsList);
this.context = context;
values = new ArrayList<String>();
values.addAll(commandsList);
typeface = getTypeface(this.context, "fonts/Roboto-Light.ttf");
inflater = LayoutInflater.from(this.context);
}
static Typeface getTypeface(Context context, String font) {
Typeface typeface = (Typeface)fontCache.get(font);
if (typeface == null) {
typeface = Typeface.createFromAsset(context.getAssets(), font);
fontCache.put(font, typeface);
}
return typeface;
}
public View getView(int position, View convertView, ViewGroup parent) {
String myText = getItem(position);
if(convertView == null) {
convertView = inflater.inflate(R.layout.hotel_row_layout, parent, false);
item = (TextView) convertView.findViewById(R.id.maps_button);
item.setTypeface(typeface);
convertView.setTag(item);
} else {
item = (TextView) convertView.getTag();
}
item.setText(myText);
//myListItem.descText.setTextSize(14);
convertView.setOnClickListener(new View.OnClickListener() {
// WORKS!
#Override
public void onClick(View view) {
Log.d("click", "Don't look at me!");
}
});
return convertView;
}
}
Fragment
public class HotelOverviewFragment extends Fragment {
private static Hashtable fontCache = new Hashtable();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_hotel_overview, container, false);
ListView list = (ListView) v.findViewById(android.R.id.list);
// Set up listview and buttons
setUp(v, list);
// Inflate the layout for this fragment
return v;
}
static Typeface getTypeface(Context context, String font) {
Typeface typeface = (Typeface)fontCache.get(font);
if (typeface == null) {
typeface = Typeface.createFromAsset(context.getAssets(), font);
fontCache.put(font, typeface);
}
return typeface;
}
public void setUp(View v, ListView l){
TextView address = (TextView) v.findViewById(R.id.content);
TextView header = (TextView) v.findViewById(R.id.header);
TextView hotelName = (TextView) v.findViewById(R.id.hotelName);
Typeface typeface = getTypeface(getActivity(), "fonts/Roboto-Light.ttf");
address.setText("some street \nZipCode, City \nCountry \nEmail \nphoneNumber");
address.setTypeface(typeface);
header.setText("Hotel info");
header.setTypeface(typeface);
header.setTextSize(20);
hotelName.setText("Hotel name");
hotelName.setTypeface(typeface);
// Set up button
ArrayList<String> n = new ArrayList<String>();
n.add(0, "More info");
// Show button
NowArrayAdapter adapter = new NowArrayAdapter(getActivity(), n);
l.setAdapter(adapter);
// THIS IS THE STUFF I'VE BEEN TRYING
try {
l.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("click", "Success");
}
});
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("click", "Success");
}
});
l.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.d("click", "Success");
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
l.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("click", "Success");
return false;
}
});
}catch (Exception e){
Log.d("click", e + "");
}
}
}
Layout xml of HotelOverviewFragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example"
android:background="#ffebebeb">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:src="#drawable/banner"
android:id="#+id/hotelBanner"
android:layout_gravity="top"
android:adjustViewBounds="false"
android:scaleType="fitXY" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hotelname"
android:id="#+id/hotelName"
android:gravity="center"
android:textSize="40dp"
android:layout_alignBottom="#+id/hotelBanner"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false"
android:textColor="#ffc4c4c4"
android:layout_marginBottom="5dp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp"
android:background="#drawable/header_card">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/header"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#android:color/primary_text_light"
android:layout_height="wrap_content"
android:text="Header"
android:layout_toRightOf="#+id/headerImage"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/headerImage"
android:src="#drawable/ic_action_live_help"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:background="#drawable/content_card">
<TextView
android:id="#+id/content"
android:layout_gravity="left|center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textColor="#android:color/primary_text_light"
android:layout_height="wrap_content"
android:text="Content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
The custom xml for a listview item
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="#drawable/content_card">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/maps_button"
android:layout_gravity="left|center_vertical"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#android:color/primary_text_light"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
<ImageView
android:src="#drawable/ic_action_arrow_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentTop="false"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="false"
android:layout_centerVertical="true"
/>
</RelativeLayout>
</LinearLayout>
Thanks in advance.
Thanks to Daniel Nugent's suggestion I got it working. Removing the convertView.setOnClickListener() is part of the answer. I think it was blocking the other listeners in the HotelOverviewFragment.
My next mistake was that I used setOnClickListener on a ListView for testing.
setOnClickListener should be used for buttons not ListViews.
So after removing setOnClickListener all the other listeners started working.
Thanks for your time.

Categories