How to disable interaction between buttons of the same layout? - java

I have two sets of layouts, populated with buttons. Is there a way to disable any interaction between buttons of the same layout? I just need nothing to happen when I click one button and then the other from the same layout. I tagged each button with " and ", for buttons that belongs to upper and lower layouts. I have 5 of each kind.
I have some interaction beetwen buttons of oposite layouts and that's working fine (actually interaction works fine between any two given buttons and that's bad), but I don't want that interaction between buttons of the same layout.
Here's my game class, not all of it, just important parts. Also, I've removed code for rest of the buttons, only left for 4 buttons, 2 for each layout, to save some space here. I import some text from sqlite database, and randomly set it to my buttons.
final OnClickListener clickListener = new OnClickListener() {
private Button buttonClicked;
public void onClick(View v) {
Button button = (Button) v;
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x003333));
if (buttonClicked == null) {
// first button is clicked
buttonClicked = button;
} else {
// second button is clicked
if (buttonClicked.getTag().equals(button.getTag())) {
button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.setEnabled(false);
button.setEnabled(false);
} else {
buttonClicked.setEnabled(false);
buttonClicked.setTextColor(Color.GRAY);
buttonClicked.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFCC99));
button.getBackground().clearColorFilter();
}
buttonClicked = null;
}
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
a1 = (Button) findViewById(R.id.bA1);
a2 = (Button) findViewById(R.id.bA2);
b1 = (Button) findViewById(R.id.bB1);
b2 = (Button) findViewById(R.id.bB2);
nextQuestion();
}
public void nextQuestion() {
TestAdapter mDbHelper = new TestAdapter(this);
mDbHelper.createDatabase();
try{
mDbHelper.open();
Cursor c = mDbHelper.getTestData(generateWhereClause());
mAnsweredQuestions.add(c.getLong(0));
ArrayList<MyStruct> labelsA = new ArrayList<MyStruct>();
ArrayList<MyStruct> labelsB = new ArrayList<MyStruct>();
labelsA.add(new MyStruct(c.getString(2), "1")); // this tag should be the same to button that matches
labelsB.add(new MyStruct(c.getString(3), "1"));
labelsA.add(new MyStruct(c.getString(4), "2"));
labelsB.add(new MyStruct(c.getString(5), "2"));
Collections.shuffle(labelsA);
Collections.shuffle(labelsB);
pitanje.setText(c.getString(1));
a1.setText(labelsA.get(0).label);
a1.setTag(labelsA.get(0).tag);
a1.setOnClickListener(clickListener);
a1.getBackground().clearColorFilter();
a1.setEnabled(true);
b1.setText(labelsB.get(0).label);
b1.setTag(labelsB.get(0).tag);
b1.setOnClickListener(clickListener);
b1.getBackground().clearColorFilter();
b1.setEnabled(true);
a2.setText(labelsA.get(1).label);
a2.setTag(labelsA.get(1).tag);
a2.setOnClickListener(clickListener);
a2.getBackground().clearColorFilter();
a2.setEnabled(true);
b2.setText(labelsB.get(1).label);
b2.setTag(labelsB.get(1).tag);
b2.setOnClickListener(clickListener);
b2.getBackground().clearColorFilter();
b2.setEnabled(true);
}
finally{
mDbHelper.close();
}
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="#drawable/background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="top|center"
android:orientation="vertical" >
<TextView
android:id="#+id/tvPitanje"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ovde ce biti postavljeno pitanje"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="360dp"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/kolona1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:gravity="top"
android:orientation="vertical"
android:paddingLeft="3dp"
android:paddingRight="2dp" >
<Button
android:id="#+id/bA1"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_gravity="clip_horizontal"
android:layout_marginBottom="1.5dp"
android:background="#drawable/buttons"
android:gravity="center_vertical|center_horizontal"
android:padding="0dp"
android:tag="l"
android:text="A1"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bA2"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A2"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
<Button
android:id="#+id/bA3"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A3"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
<Button
android:id="#+id/bA4"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A4"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
<Button
android:id="#+id/bA5"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A5"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
<Button
android:id="#+id/bA6"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A6"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
<Button
android:id="#+id/bA7"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A7"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
<Button
android:id="#+id/bA8"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:text="A8"
android:background="#drawable/buttons"
android:textColor="#ffffff"
android:layout_marginTop="1.5dp"
android:tag="l"
android:padding="0dp"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/kolona2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="50"
android:gravity="top"
android:orientation="vertical"
android:paddingLeft="2dp"
android:paddingRight="3dp" >
<Button
android:id="#+id/bB1"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_gravity="top|fill_horizontal"
android:layout_marginBottom="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B1"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB2"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B2"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB3"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B3"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB4"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B4"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB5"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B5"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB6"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B6"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB7"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginBottom="1.5dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B7"
android:textColor="#ffffff"
android:textSize="16sp" />
<Button
android:id="#+id/bB8"
android:layout_width="fill_parent"
android:layout_height="41dp"
android:layout_marginTop="1.5dp"
android:background="#drawable/buttons"
android:gravity="top|center_horizontal"
android:tag="r"
android:text="B8"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:weightSum="3" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" >
<Button
android:id="#+id/bIzlaz"
android:layout_width="80dp"
android:layout_height="42dp"
android:layout_gravity="center"
android:background="#drawable/buttons"
android:gravity="center"
android:text="Izlaz!"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="#+id/tvPoeni"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tvScore"
android:textColor="#ffffff"
android:textSize="21sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="#+id/tvVreme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30"
android:textColor="#ff0000"
android:textSize="21sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

You can use the getParent method and compare the parents of both views. If the parent is the same, then the buttons are in the same layout and nothing should happen.
Change your else:
} else {
// second button is clicked
... to an else if:
// only do stuff if buttons are in different layouts
} else if (button.getParent () != buttonClicked.getParent()) {
// second button is clicked

Related

EditText Behave as TextView like snapchat

I want to add functionality like snapchat's "add caption" in my recent project.
Expected Output: when I click on add text button, one caption bar appears with EditText and open keyboard user can feed text. If I click on layout keyboard, it closes automatically and it looks like a TextView and caption bar can move through screen at y axis.
Tried and failed: when I click on add text button, one caption bar appears with EditText, caption bar can't move through screen at y axis (if I take the TextView it works fine but not with EditText). Because I can't click on layout.
I also tried property like clickable false. But it's not working
My Question: How to show EditText as TextView while there's only touch event, while click on it works as EditText?
I fail to take click and touch on layout after adding edittext text value.
here's my code:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rel_Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:clickable="true">
<FrameLayout
android:id="#+id/frame_cameraHolder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/iv_cameraMain"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<RelativeLayout
android:id="#+id/rel_cameraTitleHolder1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp">
<ImageButton
android:id="#+id/ib_cameraClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_close_white" />
<ImageButton
android:id="#+id/ib_cameraForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="24dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_forward" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_cameraTitleHolder2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:visibility="gone">
<ImageButton
android:id="#+id/ib_cameraCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_close_white" />
<ImageButton
android:id="#+id/ib_cameraBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_back" />
<ImageButton
android:id="#+id/ib_cameraStickers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toLeftOf="#+id/ib_cameraDraw"
android:background="#android:color/transparent"
android:src="#drawable/ic_sticker" />
<ImageButton
android:id="#+id/ib_cameraDraw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toLeftOf="#+id/ib_cameraText"
android:background="#android:color/transparent"
android:src="#drawable/ic_draw" />
<ImageButton
android:id="#+id/ib_cameraText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="24dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_text" />
</RelativeLayout>
<!--<uz.shift.colorpicker.LineColorPicker
android:id="#+id/color_picker"
android:layout_width="match_parent"
android:layout_height="60dp"
app:orientation="horizontal"
android:visibility="gone"/>-->
<RelativeLayout
android:id="#+id/rel_cameraTextHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:visibility="gone">
<ImageButton
android:id="#+id/ib_cameraTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_fontstyle" />
<TextView
android:id="#+id/ib_cameraDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="24dp"
android:text="Done"
android:textColor="#color/white"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
<!--diff-->
<RelativeLayout
android:id="#+id/rel_cameraHolder1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="visible">
<ImageButton
android:id="#+id/ib_cameraflash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_flash" />
<Button
android:id="#+id/btn_cameraCapturePic"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerHorizontal="true"
android:background="#drawable/btn_capture" />
<ImageButton
android:id="#+id/ib_cameraReverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_reverse" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_cameraHolder2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<FrameLayout
android:id="#+id/frame_cameraTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp">
<ImageButton
android:id="#+id/ib_cameraTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="24dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_blanck_timer" />
<TextView
android:id="#+id/text_cameraTimerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="34dp"
android:layout_marginTop="6dp"
android:text="1"
android:textColor="#color/white"
android:textSize="8dp"
android:textStyle="bold" />
</FrameLayout>
<ImageButton
android:id="#+id/ib_cameraSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toRightOf="#+id/frame_cameraTimer"
android:background="#android:color/transparent"
android:src="#drawable/ic_save" />
<ImageButton
android:id="#+id/ib_cameraYourStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toRightOf="#+id/ib_cameraSave"
android:background="#android:color/transparent"
android:src="#drawable/ic_add" />
<ImageButton
android:id="#+id/ib_cameraSaveForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="24dp"
android:background="#drawable/btn_capture"
android:src="#drawable/ic_forward" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_cameraDeleteHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<ImageButton
android:id="#+id/ib_cameraDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_delete" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_EdtAddedText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:orientation="horizontal"/>
</RelativeLayout>
MainActivity.java
private void setAddedEditTextDynamically() {
mRelativeLayoutHolder2.setVisibility(View.GONE);
//create dynamic edit text
RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
final EditText edtAddedText = new EditText(MainActivity.this);
lparams.addRule(RelativeLayout.CENTER_IN_PARENT);
edtAddedText.setLayoutParams(lparams);
edtAddedText.setTextColor(getResources().getColor(R.color.white));
edtAddedText.setGravity(Gravity.CENTER_HORIZONTAL);
// add edittext to rel layout
mRelEdtAddedText.addView(edtAddedText);
mRelEdtAddedText.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
mRelEdtAddedText.setOnTouchListener(new View.OnTouchListener() {
PointF DownPT = new PointF(); // Record Mouse Position When Pressed Down
PointF StartPT = new PointF(); // Record Start Position of 'img'
#Override
public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:
PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
// mLinMain.setX((int)(StartPT.x+mv.x));
mRelEdtAddedText.setX(10);
mRelEdtAddedText.setY((int) (StartPT.y + mv.y));
StartPT = new PointF(mRelEdtAddedText.getX(), mRelEdtAddedText.getY());
break;
case MotionEvent.ACTION_DOWN:
DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(mRelEdtAddedText.getX(), mRelEdtAddedText.getY());
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
return true;
}
});
}

TextView text animation is restarted if the text is changed in another TextView

In TextView1 text animation runs from right to left, and in TextView2 constantly changing text. The problem is that when I perform TextView2.setText ( "...") in the text animation TextView1 restarted. Is it possible to prevent the restart of the animation?
XML code TextView1:
<TextView
android:id="#+id/artistAlbum"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingTop="2dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="text text text text text text text"
android:textSize="14sp" />
Java code initialization TextView1:
final TextView textView1 = (TextView) rootView.findViewById(R.id.textView1);
textView1.setSelected(true);
XML code TextView2:
<TextView
android:id="#+id/seekSongDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:clickable="true"
android:paddingBottom="12dp"
android:paddingEnd="2dp"
android:paddingStart="10dp"
android:paddingTop="12dp"
android:text="0%"
android:textSize="20sp" />
XML code:
<TextView
android:id="#+id/fullSongDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="#color/background"
android:clickable="true"
android:paddingBottom="12dp"
android:paddingEnd="10dp"
android:paddingStart="2dp"
android:paddingTop="12dp"
android:text="3:15"
android:textSize="20sp" />
<org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
android:id="#+id/seekDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="#id/seekSongDuration"
android:layout_toEndOf="#id/seekSongDuration"
android:layout_toStartOf="#id/fullSongDuration"
android:paddingBottom="10dp"
android:paddingTop="10dp"
app:dsb_trackHeight="3dp" />
<com.andexert.library.RippleView
android:id="#id/butPlayPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/seekSongDuration"
android:layout_centerHorizontal="true"
android:background="#color/background"
app:rv_alpha="100"
app:rv_centered="true"
app:rv_color="#android:color/white"
app:rv_framerate="15"
app:rv_rippleDuration="300">
<ImageView
android:id="#+id/imgPlayPause"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/ic_play_circle_outline_black_48dp" />
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:id="#+id/butShufle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/seekSongDuration"
android:layout_alignTop="#id/butPlayPause"
android:background="#color/background"
app:rv_alpha="150"
app:rv_color="#android:color/white"
app:rv_framerate="15"
app:rv_rippleDuration="300">
<ImageView
android:id="#+id/imgShufle"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:src="#drawable/ic_shuffle_black_36dp" />
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:id="#+id/butPreviosSong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/seekSongDuration"
android:layout_alignTop="#id/butPlayPause"
android:layout_toEndOf="#id/butShufle"
android:layout_toStartOf="#id/butPlayPause"
android:background="#color/background"
app:rv_alpha="100"
app:rv_color="#android:color/white"
app:rv_framerate="20"
app:rv_rippleDuration="300"
app:rv_type="rectangle">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_fast_rewind_black_48dp" />
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:id="#+id/butLooping"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/seekSongDuration"
android:layout_alignParentEnd="true"
android:layout_alignTop="#id/butPlayPause"
android:background="#color/background"
app:rv_alpha="150"
app:rv_color="#android:color/white"
app:rv_framerate="20"
app:rv_rippleDuration="300">
<ImageView
android:id="#+id/imgLoopReaped"
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:src="#drawable/ic_repeat_black_36dp" />
</com.andexert.library.RippleView>
<com.andexert.library.RippleView
android:id="#+id/butNextSong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/seekSongDuration"
android:layout_alignTop="#+id/butPlayPause"
android:layout_toEndOf="#id/butPlayPause"
android:layout_toStartOf="#id/butLooping"
android:background="#color/background"
app:rv_alpha="100"
app:rv_color="#android:color/white"
app:rv_framerate="20"
app:rv_rippleDuration="300"
app:rv_type="rectangle">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_fast_forward_black_48dp" />
</com.andexert.library.RippleView>
<RelativeLayout
android:id="#id/currentSongLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_above="#+id/butPlayPause"
android:background="#color/backgroundCurrentTrack"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
<com.andexert.library.RippleView
android:id="#+id/butSettingCurrentSong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
app:rv_alpha="100"
app:rv_centered="true"
app:rv_color="#android:color/black"
app:rv_framerate="15"
app:rv_rippleDuration="300">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="8dp"
android:src="#drawable/ic_more_circle_vert_black_36dp" />
</com.andexert.library.RippleView>
<ImageView
android:id="#+id/iconCurrentPlaylist"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="5dp"
android:src="#drawable/ic_playlist_play_black_36dp" />
<TextView
android:id="#+id/txtNumberSongs"
android:layout_width="wrap_content"
android:layout_height="23dp"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:layout_toEndOf="#id/iconCurrentPlaylist"
android:background="#drawable/shape_ellipse"
android:paddingEnd="6dp"
android:paddingStart="6dp"
android:paddingTop="3dp"
android:text="1/1"
android:textAlignment="center"
android:textColor="#color/grayLite"
android:textSize="12sp" />
<TextView
android:id="#+id/songTitle"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_toEndOf="#id/txtNumberSongs"
android:layout_toStartOf="#id/butSettingCurrentSong"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="5dp"
android:paddingTop="2dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Title"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/artistAlbum"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_below="#id/songTitle"
android:layout_toEndOf="#id/iconCurrentPlaylist"
android:layout_toStartOf="#id/butSettingCurrentSong"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingTop="2dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Artist - Album"
android:textSize="14sp" />
</RelativeLayout>
Java code:
private TextView songArtistAlbum;
private TextView txtSeek;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
songArtistAlbum = (TextView) rootView.findViewById(R.id.artistAlbum);
songArtistAlbum.setSelected(true);
txtSeek = (TextView) rootView.findViewById(R.id.seekSongDuration);
...
}
private DiscreteSeekBar.OnProgressChangeListener onDurationProgressChangeListener = new DiscreteSeekBar.OnProgressChangeListener() {
#Override
public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) {
if (!fromUser) {
txtSeek.setText(Total.msecTo_MM_SS(seekBar.getProgress()));
}
}
#Override
public void onStartTrackingTouch(DiscreteSeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(DiscreteSeekBar seekBar) {
txtSeek.setText(Total.msecTo_MM_SS(seekBar.getProgress()));
}
};
Thanks in advance.
Try to wrap your TextView1 with LinearLayout.
Check Activity class TextView object and its assign id.

The keyboard is coming upon the EditText field & thus hiding it. How to prevent the keyboard from hiding the EditText field?

My EditText is at the bottom of screen, so when I'm tapping on it to edit it, the keyboard is hiding it. I want that when I tap on EditText, the keyboard should remain below it & should not hide it.
Here's the link to the screenshot showing EditText before tapping on it: http://imgur.com/cgme1HT
Here's the link to the screenshot after tapping on EditText (the EditText field is below the keyboard now): http://imgur.com/nloFrkn
Here's my SettingUpUserProfile.java file's code:
public class SettingUpUserProfile extends AppCompatActivity {
public static final int TAKE_PHOTO_REQUEST = 0;
public static final int PICK_PHOTO_REQUEST = 1;
private static final int RESULT_LOAD_IMG = 2;
String imgDecodableString;
protected ImageView userProfilePicture;
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting_up_user_profile);
userProfilePicture = (ImageView) findViewById(R.id.userProfilePicture);
userProfilePicture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(SettingUpUserProfile.this);
builder.setTitle(null);
builder.setItems(R.array.pickImage_options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int position) {
switch (position) {
case 0:
Intent intentCaptureFromCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intentCaptureFromCamera, TAKE_PHOTO_REQUEST);
break;
case 1:
Intent chooseFromGalley = new Intent(Intent.ACTION_GET_CONTENT);
chooseFromGalley.setType("image/*");
startActivityForResult(chooseFromGalley, PICK_PHOTO_REQUEST);
break;
}
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
// Log.d(TAG, String.valueOf(bitmap));
ImageView imageView = (ImageView) findViewById(R.id.userProfilePicture);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
}
Here's my activity_setting_up_user_profile.xml file's code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_purple"
tools:context="com.abc.xyz.SettingUpUserProfile">
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"/>
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp"
android:gravity="center_horizontal|center_vertical"/>
<EditText
android:id="#+id/userName"
android:background="#drawable/phone_number_edit_text_design"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null"
android:inputType="textPersonName"/>
<Button
android:id="#+id/buttonAllSet"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginTop="20dp"
android:text="#string/button_allSet"
android:textStyle="bold"
android:textColor="#color/light_purple"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:gravity="center_horizontal|center_vertical"/>
</RelativeLayout>
I really have no clue about what to do here!
Please let me know.
I'm new to StackOverflow, so please cooperate.
Thanks in advance.
I had the same issue where the softkeyboard was on top of the EditText views which were placed on the bottom of the screen. I was able to find a solution by adding a single line to my AndroidManifest.xml file's relevant activity.
Put layout inside a ScrollView.
android:windowSoftInputMode="adjustResize|stateHidden"
This is how the whole activity tag looks like:
<activity
android:name="com.my.MainActivity"
android:screenOrientation="portrait"
android:label="#string/title_activity_main"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
Here the most important value is the adjustResize. This will shift the whole UI up to give room for the softkeyboard.
Simply use a ScrollView as the parent view in your xml file.
Options-1
Try using android:windowSoftInputMode="adjustPan" in activity in AndroidManifest.xml
Options-2
Use ScrollView as parent in xml. Replace your xml with this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.abc.xyz.SettingUpUserProfile" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_purple">
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="30sp"
android:gravity="center_horizontal|center_vertical"/>
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp"
android:gravity="center_horizontal|center_vertical"/>
<EditText
android:id="#+id/userName"
android:background="#drawable/phone_number_edit_text_design"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null"
android:inputType="textPersonName"/>
<Button
android:id="#+id/buttonAllSet"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginTop="20dp"
android:text="#string/button_allSet"
android:textStyle="bold"
android:textColor="#color/light_purple"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:gravity="center_horizontal|center_vertical"/>
</RelativeLayout>
</ScrollView>
Thank you all for your answers.
I solved the problem by changing my activity_setting_up_user_profile.xml file's code to this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/light_purple"
tools:context="com.abc.xyz.SettingUpUserProfile" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp" />
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="80dp"
android:background="#drawable/phone_number_edit_text_design"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null" />
<Button
android:id="#+id/buttonAllSet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:layout_marginTop="20dp"
android:background="#color/white"
android:gravity="center_horizontal|center_vertical"
android:text="#string/button_allSet"
android:textColor="#color/light_purple"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
This was COOL!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.abc.xyz.SettingUpUserProfile" >
<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"
android:background="#color/light_purple" >
<TextView
android:id="#+id/settingUpUserProfileText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText1"
android:textColor="#color/white"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/userProfilePicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#+id/settingUpUserProfileText1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="100dp"
android:clickable="true"
android:src="#drawable/ic_face_white_48dp" />
<TextView
android:id="#+id/settingUpUserProfileText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userProfilePicture"
android:layout_marginTop="5dp"
android:gravity="center_horizontal|center_vertical"
android:text="#string/settingUpUserProfileText2"
android:textColor="#color/white"
android:textSize="15sp" />
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/settingUpUserProfileText2"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="80dp"
android:background="#drawable/phone_number_edit_text_design"
android:gravity="center_horizontal|center_vertical"
android:hint="#string/hint_userName"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#E0E0E0"
android:textCursorDrawable="#null" />
<Button
android:id="#+id/buttonAllSet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_marginEnd="120dp"
android:layout_marginStart="120dp"
android:layout_marginTop="20dp"
android:background="#color/white"
android:gravity="center_horizontal|center_vertical"
android:text="#string/button_allSet"
android:textColor="#color/light_purple"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

don't work onClick in buttons at list_view height = match_parent

I think because my ListView is set to layout_height="match_parent", the Buttons are not called onClick method.
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null) {
Log.d(TAG_DEBUG,"0");
} else{
Button button1 = (Button) convertView.findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG_DEBUG, "TEST");
}
});
}
return super.getView(position, convertView, parent);
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/num_ord"
android:background="#drawable/fon_ord"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/title_ord"
android:textColor="#000000"
android:typeface="serif"
android:textStyle="normal|italic"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sum:"
android:id="#+id/textView2"
android:textColor="#FFFFFF"
android:background="#drawable/fon_ord"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/sum_ord"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="-24dp"
android:textColor="#000000"
android:layout_marginLeft="64dp"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Col:"
android:id="#+id/textView3"
android:textColor="#FFFFFF"
android:background="#drawable/fon_ord"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/count_ord"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="-24dp"
android:textColor="#000000"
android:layout_marginLeft="106dp"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DD:"
android:id="#+id/textView4"
android:textColor="#ffffff"
android:background="#drawable/fon_ord"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/date_ord"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="-24dp"
android:textColor="#000000"
android:layout_marginLeft="50dp"
android:focusable="false" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="127dp"
android:layout_height="36dp"
android:text="Del"
android:id="#+id/button1"
android:layout_marginTop="20dp"
android:focusable="false" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="127dp"
android:layout_height="36dp"
android:text="Ed"
android:id="#+id/button2"
android:layout_gravity="right"
android:layout_marginTop="-37dp"
android:layout_marginRight="4dp"
android:focusable="false" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/list_orders"
android:focusable="true" />
</LinearLayout>
When I press the buttons, nothing happens, why?

How to make the popup window BG blur

In my app I am using popup window it looks like this, But the background for the popup window is not blur, how do I make it appear blur.
Here is the code,
View v1 = inflatter.inflate(R.layout.problemlistmenu_popup, null);
v1.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int height1 = v1.getMeasuredHeight();
clickOnProblemName = new PopupWindow(showProblemMenu(details), (int) (width * 0.8), height1, true);
clickOnProblemName.showAtLocation(mainlayout, Gravity.CENTER, 0, 0);
showProblemMenu
protected View showProblemMenu(String details) {
View v = null;
v = inflatter.inflate(R.layout.problemlistmenu_popup, null);
return v;
}
And here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/silver002"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#drawable/headerstyle1" >
<TextView
android:id="#+id/tvHeaderText"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text=""
android:textColor="#android:color/white"
android:textSize="12dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_marginTop="4dp"
android:gravity="right|center_vertical" >
<TextView
android:id="#+id/tvCancel"
android:layout_marginRight="3dp"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_marginTop="2dp"
android:background="#drawable/backgroundstyle_btn1"
android:layout_gravity="right"
android:text="Cancel"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/tvChronic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:textColor="#android:color/black"
android:text=""
android:textStyle="bold"
android:background="#drawable/row_selector"
android:textSize="14dp" />
<TextView
android:id="#+id/tvResolved"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:text="Change to Resolved"
android:textStyle="bold"
android:background="#drawable/row_selector_alternative"
android:textColor="#android:color/black"
android:textSize="14dp" />
<TextView
android:id="#+id/tvProblemName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:text="Edit Problem Name"
android:textStyle="bold"
android:background="#drawable/row_selector"
android:textColor="#android:color/black"
android:textSize="14dp" />
<TextView
android:id="#+id/tvComments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:text="Edit Comments"
android:textStyle="bold"
android:background="#drawable/row_selector_alternative"
android:textColor="#android:color/black"
android:textSize="14dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Thanks in advance.
There is a really good tutorial here that shows you how to do this:
http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/
May this help
mPopupWindow.setTouchable(true);
mPopupWindow.setFocusable(false);
mPopupWindow.setOutsideTouchable(false);

Categories