呼叫从ListViewItem的活动不失tabNavigation [英] Call an activity from a listViewItem Without losing the tabNavigation
问题描述
我是小白在Android的发展,我尝试做一个简单的应用程序,有关某些产品和材料的细节。
I'm noob on android development, and im trying to do a simple app, for details about certain products and stuff.
我有以下布局:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
有2个标签上tabHost导航,每一个扩展片段像这样
There are 2 tabs on that tabHost navigation, each one extends fragment like this
package co.com.smartmedia.vademecumtg;
import co.com.smartmedia.vademecumtg.R;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class LineasTab extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab2, container, false);
}
}
在该导航我有ListView的第一个标签,并将该列表中的每个项目,必须调用另一项活动,将显示其详细信息。
In the first tab of that navigation i have a listView, and each item of that list, must call another activity that will show details about it.
即时调用从itemClickListener这个方法调用一个新的活动:
im calling a new activity by calling this method from an itemClickListener:
public void intentForMedView(int pos){
Log.w("debbuging", "start");
Intent intent = new Intent(getActivity().getApplicationContext(), MedViewActivity.class);
intent.putExtra(EXTRA_MEDTITLE, array_sort.get(pos).getNombre());
intent.putExtra(EXTRA_MEDCONTENT, array_sort.get(pos).getLinea());
Log.w("debbuging", "send intent"+intent);
startActivity(intent);
}
和我打电话的活动如下:
and the activity that i'm calling is the following:
package co.com.smartmedia.vademecumtg;
import co.com.smartmedia.vademecumtg.R;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MedViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_med_view);
Intent intent = getIntent();
String title = intent.getStringExtra(MedicamentosTab.EXTRA_MEDTITLE);
setTitle(title);
TextView text = (TextView) findViewById(R.id.text);
String lineName = intent.getStringExtra(MedicamentosTab.EXTRA_MEDCONTENT);
text.setText(lineName);
}
}
我的问题是:
My problem is:
在详细活动显示,我的导航消失(在tabHost导航),而我不希望它....
When the detail activity is shown, my navigation Disappears (the tabHost navigation), and i don't want it....
一些提示或如何做到这一点?
some tips or ways to do it ?
thaks ...
thaks...
推荐答案
我现在的答案,要完成这种架构的方法,就是用 FragmentTransaction
I got the answer now, The way to accomplish this architecture, is to use FragmentTransaction
http://developer.android.com/guide/components/fragments.html
因为这是没有必要的另一项活动......刚刚与UI的片段播放。
Cause it isn't necessary another activity... just play with the fragments of the UI.
FragmentManager fragmentManager = getFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
和照顾了Android版本的原因 android.support.v4.app.FragmentManager
无法转换为 android.app.FragmentManager
And take care with the android version cause android.support.v4.app.FragmentManager
cannot cast to the android.app.FragmentManager
希望这是有益
这篇关于呼叫从ListViewItem的活动不失tabNavigation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!