简体   繁体   中英

(Tabbar hide) when the user go to next screen from Tabbar in Android?

Currently i am working in Android application, Using Tabbar to set five tabs, then i select third tab it shows ListView, the user select ListItem to go next screen (Using Intent), At the same time Tabbar is hidden, so i tried to show the tabbar in that screen, but i didn't know that? please help me

Thanks in Advance

I'd been also having the same problem. With use of this ActivityGroup class help me to do my requirement. You can also try with below code.

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();
      }  
  }
}

Hope this helps you.

try this

Activity1 that contain your list

    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);
    }
                        });
}

and Activity2 must extends Activity

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

look at this example here

try to create your listadapter as separate class like this

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;
    }
}

in your activity call your adapter for fill your list

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM