(Tabbar隐藏)当用户从Android中的Tabbar转到下一个屏幕时?

时间:2012-08-22 09:25:23

标签: android listview android-tabhost

目前我在Android应用程序中工作,使用Tabbar设置五个选项卡,然后我选择第三个选项卡显示ListView,用户选择ListItem进入下一个屏幕(使用Intent),同时Tabbar被隐藏,所以我试图在该屏幕中显示标签栏,但我不知道?请帮帮我

先谢谢

2 个答案:

答案 0 :(得分:1)

我也遇到了同样的问题。使用this ActivityGroup课程可以帮助我完成我的要求。您也可以尝试使用以下代码。

public class TabGroupActivity extends ActivityGroup {

    private ArrayList<String> mIdList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
        if (mIdList == null) mIdList = new ArrayList<String>();
    }

    /**
     * This is called when a child activity of this one calls its finish method. 
     * This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
     * and starts the previous activity.
     * If the last child activity just called finish(),this activity (the parent),
     * calls finish to finish the entire group.
     */
  @Override
  public void finishFromChild(Activity child) {
      LocalActivityManager manager = getLocalActivityManager();
      int index = mIdList.size()-1;

      if (index < 1) {
          finish();
          return;
      }

      manager.destroyActivity(mIdList.get(index), true);
      mIdList.remove(index); index--;
      String lastId = mIdList.get(index);
      Intent lastIntent = manager.getActivity(lastId).getIntent();
      Window newWindow = manager.startActivity(lastId, lastIntent);
      setContentView(newWindow.getDecorView());
  }

  /**
   * Starts an Activity as a child Activity to this.
   * @param Id Unique identifier of the activity to be started.
   * @param intent The Intent describing the activity to be started.
   * @throws android.content.ActivityNotFoundException.
   */
  public void startChildActivity(String Id, Intent intent) {     
      Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
      if (window != null) {
          mIdList.add(Id);
          setContentView(window.getDecorView()); 
      }    
  }

  /**
   * The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
   * from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
   */
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
          return true;
      }
      return super.onKeyDown(keyCode, event);
  }

  /**
   * Overrides the default implementation for KeyEvent.KEYCODE_BACK 
   * so that all systems call onBackPressed().
   */
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          onBackPressed();
          return true;
      }
      return super.onKeyUp(keyCode, event);
  }

  /**
   * If a Child Activity handles KeyEvent.KEYCODE_BACK.
   * Simply override and add this method.
   */
  @Override
  public void  onBackPressed  () {
      int length = mIdList.size();
      if ( length > 1) {
          Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
          current.finish();
      }  
  }
}

希望这会对你有所帮助。

答案 1 :(得分:0)

试试这个

包含您的列表的活动1

    Activity1 extends ActivityGroup {

    ......

    yourListView.setOnItemClickListener(new OnItemClickListener() {

     public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
    Intent activity2Intent = new Intent(v.getContext(), Activity2.class);
    StringBuffer urlString = new StringBuffer();
    replaceContentView("activity2", activity2Intent);
    }
                        });
}

和Activity2必须扩展Activity

public class Activity2 extends Activity {
........
}

查看此示例here

尝试将listadapter创建为单独的类,如此

public class YourListAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    List<String> values;

    public YourListAdapter(Context context, List<String> values) {

        this.values = values;
        mInflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return values.size();
    }

    public Object getItem(int position) {
        return values.get(position);
    }

    public long getItemId(int position) {
        return 0;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        View v = mInflater.inflate(R.layout.yourListRow, null);

        TextView txtTitre = (TextView) v.findViewById(R.id.rowTxt);
        txtTitre.setText( values.get(position););

        return v;
    }
}

在您的活动中调用您的适配器填写您的列表

yourListView = (ListView) findViewById(R.id.yourListView);
YourListAdapter lAdapter= new YourListAdapter(YourActivity.this, YourListStrings);
yourListView.setAdapter(lAdapter);