Philip Andersson
Philip Andersson

Reputation: 100

TextView setText from another class

My problem is that i've a tabhost with two tabs. The first is a listview and the second only have two textviews.

What i want is when i click on an item in the listview on tab one, the array position id (int) should be sent to tab/class two, where there is an array who fetches a text by the position id that was sent.

The switching of tabs is done, but i fail everytime i try to send the position-id.

This is how i send it:

TAB ONE:

//This function is called when i click a listitem
public void setDetails(String Text, long arr_id){
        Detail detail = new Detail();
        detail.setDetail(); // right now i don't send the parameters because it wont even work with or without it.
    }

TAB TWO:

TextView descr;
TextView title;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail);

    descr = (TextView)findViewById(R.id.desc);
    title = (TextView)findViewById(R.id.title);

}

public void setDetailText(String Text){
    descr.setText(Text);
}
public void setDetailTitle(String Text){
    title.setText(Text);
}

public void setDetail(){
    this.setDetailTitle("example text");
    this.setDetailText("example text2");
}

I want to set the text on tab two BEFORE it switch to tab two. This works if i use SetDetail() and setDetailTitle() in the same tab/class, but not in another.

I've googled my ass off, please help me

Upvotes: 0

Views: 877

Answers (1)

Franco
Franco

Reputation: 7475

i do this in my code using getParent() or getActivity() methods in my TabActivity and inner Activitys, cause if we use a TabActivity (wich subclass the ActivityGroup class) we can obtain the 'TextActivity' using ActivityManager and obtain the activity instance, so, here we can call the setDetail() method, and this will execute before the Activity is showed,

in your ListActivity do something like this

((MyTextActivity)((MyTabActivity)getParent()).getLocalActivityManager().getActivity(ACTIVITY_ID)).setDetail();

this works only if in you start the childs activity within your TabActivity with:

intent = new Intent(ACTIVITY_ID).setClass(this, MyMapActivity.class);
        getLocalActivityManager().startActivity(ACTIVITY_ID, intent);

Upvotes: 1

Related Questions