The basic concept is just consider that you have a layout file hello.xml
and two java class one is One.java
and other is Two.java
. now you have a button in your xml file
and also have the listener method "clickButton
" in One.java
class and Two.java
. so which one is fired ? hear you need to configure(inflate
) java class and layout file .suppose you inflate hello.xml
with One.java so your listener method will goes to One.java
class . But Yes you can write a method (for button's activity) in Two.java , then you need some additional task , you must make an object of Two.java
class inside One.java
class and just call this method inside buttons event method of One.java
class . other wise nothing will happen .
Thank you
Java class is ignored by activity layout when layout is inflated in other class
-
20-07-2023 - |
Question
So i've been working on my project, first android project to be specific, and i kinda progressed in stuff that i want, i used fragments and all pretty successfully, but just recently i added a PopupWindow and use it as a window for displaying a music player in it, but when i created activity for that player and inflated the layout of this player activity in my other class, the main class that was created with player activity is now ignored, i checked with a button click event, and strangely, button click event is working when called from that other class where i inflated the layout of player activity, this is messy and all, but my question would be this - is there a way to inflate/show a popup window with a layout of my player activity while being able to have all methods and events in that same player activity java class? Here is a snippet that inflates layout from player activity:
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.activity_play,null,false);
popup = new PopupWindow(context);
popup = new PopupWindow(layout, 480, 250, true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.setAnimationStyle(R.style.Animation);
popup.showAtLocation(layout,Gravity.NO_GRAVITY,50,550);
The class that i call it from extends ListFragment. And here is a snippet from the player activity class that is ignored
public class PlayAct extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
ImageButton imbPlay = (ImageButton)findViewById(R.id.imbPlay);
imbPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(PlayAct.this);
builder.setMessage("THIS IS A MESSAGE FROM NEW PLAYER ACTIVITY");
builder.setTitle("MESSAGE");
AlertDialog alert = builder.create();
alert.show();
}
});
}
}
I hope you can help me, and sorry if i posted something inccorectly as it's my first post on stackoverflow.
Solution