Inflate Layout from activity that is not it's parent



I have two Activities:



  1. EntryActivity

  2. chatMessages


In the past I was setContentView() in onCreate(...) of the chatMessages Activity, & I was pass a parameter Like (R.layout.messenger) (inflating is expensive process") but, because I use chatMessages offten I decide to Inflate messenger.XML in another activity (EntryActivity) Like this



public class EntryActivity extends FragmentActivity{
public static View ChatView;
.....
.....
LayoutInflater inflater = getLayoutInflater();
ChatView= inflater.inflate(R.layout.messenger, null);
....
}


and in chatMessages I do:



setContentView(EntryActivity.ChatView); // NOW NO NEED FOR INFLATING


after this change its work "fine" but all the ("OnClick" handlers) in my messenger.xml looking for "thier" methods in Entryavtivity instead chatMessages Activity. example : in messenger.xml



<ImageButton
android:layout_width="42dp"
android:layout_height="42dp"
android:id="@+id/imageButton"
android:padding="5dp"
android:layout_margin="5dp"
android:onClick="pickMedia"
android:background="@drawable/headertop"
android:src="@drawable/attt"
android:scaleType="fitCenter" />


When I tab the Button I get this message: Could not find a method show_smily(View) in the activity .EntryActivity


but the onclick handler (pickMedia(){...}) is exist in ChatConversation Activity. and the messenger.xml associated to ChatConversation Activity:



tools:context="com.Esmaeel.chatMessages">


and in design view is see that the layout associated to chatMessages:


design view


I dont want to move all the events handlers to EntryActivity How may I make the app look for the handler in chatMessages???


No comments:

Post a Comment