0

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

提前致谢

4

2 回答 2

1

我也遇到了同样的问题。使用这个 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();
      }  
  }
}

希望这对您有所帮助。

于 2012-08-22T09:36:22.360 回答
0

试试这个

包含您的列表的 Activity1

    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 {
........
}

在这里看这个例子

尝试像这样将您的 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);
于 2012-08-22T09:42:42.580 回答