开发者

Tab Application Development

I wish to create a tab application in Android. I wish to basically have four tabs in my application. Namely, Home, Compose, Inbox, Sent. I started with a TabContainer extending TabActivity, is this a correct approach. Since i will be having MenuItem, which i used be having multiple views for Inbox, as such List of inbox, i sud be able to read, and then delete and all. I wish to know how do I approach? Basically i wish to make an application similar to gmail.

Any ideas, or direction might help me

public class Inbox extends ListActivity{
    private ProgressDialog progressDialog = null; 
    private ArrayList<EmailElement> emailElement = null;
    private InboxAdapter inboxAdapter;
    private CheckBoxWithInboxList newInboxAdapter;
    private Runnable beforeFetchingEmail;
    private TextView emailFromTextView = null;
    private TextView emailSubjectTextView = null;
    ListView listView;
    private static int mode = 0;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.inbox);

        mode = this.getIntent().getIntExtra("EDIT_MODE", -1);
        Log.i("EDITMODE", String.valueOf(mode));
        emailElement = new ArrayList<EmailElement>();
        if(mode ==0 || mode==-1){
         this.inboxAdapter = new InboxAdapter(this, R.layout.inbox_row, emailElement);
         setListAdapter(inboxAdapter);
        }else{
            this.newInboxAdapter = new CheckBoxWithInboxList(this, R.layout.inbox_row, emailElement);
            setListAdapter(newInboxAdapter);
        }
        beforeFetchingEmail = new Runnable() {
            @Override
            public void run() {
                    getEmails();
                }
            };
            Thread thread =  new Thread(null, beforeFetchingEmail, "MagentoBackground");
            thread.start();
            progressDialog = ProgressDialog.show(Inbox.this,"Please wait...",
                    "Retrieving Emails ...", true);
            listView = getListView();
            listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parentView, View view,
                        int position, long id) {

                    }
                });
}
 private Runnable returnRes = new Runnable() {

        @Override
        public void run() {
            if(emailElement != null && emailElement.size() > 0){
                if(mode==0 || mode==-1){
                    inboxAdapter.notifyDataSetChanged();
                    for(int i=0;i<emailElement.size();i++){
                        inboxAdapter.add(emailElement.get(i));
                    }
       开发者_开发问答             progressDialog.dismiss();
                    inboxAdapter.notifyDataSetChanged();
                }else{
                    newInboxAdapter.notifyDataSetChanged();
                    for(int i=0;i<emailElement.size();i++){
                        newInboxAdapter.add(emailElement.get(i));
                    }
                    progressDialog.dismiss();
                    newInboxAdapter.notifyDataSetChanged();
                }

            }
        }
    };
 private void getEmails(){
     try{
         emailElement = new ArrayList<EmailElement>();
         EmailElement ee0 = new EmailElement();
         ee0.setFrom("Robin Thapa");
         ee0.setSubject("Urgent Meeting");
         emailElement.add(ee0);
         EmailElement ee1 = new EmailElement();
         ee1.setFrom("Deepak Thapa");
         ee1.setSubject("Staff meeting @Sunday");
         emailElement.add(ee1);
         Thread.sleep(5000);
     }catch(Exception ex){

     }
     runOnUiThread(returnRes);
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu){
       MenuInflater menuInflater = getMenuInflater();
       menuInflater.inflate(R.menu.inbox_menu, menu);
       return true;
   }
 @Override
  public boolean onOptionsItemSelected(MenuItem item){
       switch(item.getItemId()){
       case R.id.inboxEdit:
               Intent intent = new Intent(this,EmailClient.class);
               intent.putExtra("tabId", 2);
               intent.putExtra("EDIT_MODE", 1);
               startActivityForResult(intent, Intent.FILL_IN_DATA);
           return true;
       case R.id.inboxRefresh:
           return true;
       case R.id.inboxNext:
           return true;
       case R.id.inboxPrevious:
           return true;
        }
       return false;
}
private class InboxAdapter extends ArrayAdapter<EmailElement>{
     private ArrayList<EmailElement> items;

     public InboxAdapter(Context context,int textViewResourceId, 
                ArrayList<EmailElement> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }
      @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View view = convertView;
                if (view == null) {
                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    view = vi.inflate(R.layout.inbox_row, null);
                }
                EmailElement o = items.get(position);
                if (o != null) {
                    CheckBox emailCheckBox = (CheckBox)view.findViewById(R.id.inboxCheckBoxId);
                    emailCheckBox.setVisibility(View.INVISIBLE);
                        emailFromTextView = (TextView) view.findViewById(R.id.inboxEmailFrom);
                        emailSubjectTextView = (TextView) view.findViewById(R.id.inboxEmailSubject);
                         if (emailFromTextView != null){
                             emailFromTextView.setText("From: "+o.getFrom());
                        }
                        if(emailSubjectTextView != null){
                            emailSubjectTextView.setText("Sub: ["+ o.getSubject()+"]");
                        }
                }
                return view;
        }
 }


private class CheckBoxWithInboxList extends ArrayAdapter<EmailElement>{
 private ArrayList<EmailElement> items;
 public CheckBoxWithInboxList(Context context,int textViewResourceId, 
            ArrayList<EmailElement> items) {
    super(context, textViewResourceId, items);
    this.items = items;
}
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
         View view = convertView;
         if (view == null) {
             LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             view = vi.inflate(R.layout.inbox_row, null);
         }
         EmailElement o = items.get(position);
         if (o != null) {
            CheckBox emailCheckBox = (CheckBox)view.findViewById(R.id.inboxCheckBoxId);
            emailCheckBox.setVisibility(View.VISIBLE);
                emailFromTextView = (TextView) view.findViewById(R.id.inboxEmailFrom);
                 emailSubjectTextView = (TextView) view.findViewById(R.id.inboxEmailSubject);
                  if (emailFromTextView != null){
                     emailFromTextView.setText("From: "+o.getFrom());
                 }
                 if(emailSubjectTextView != null){
                    emailSubjectTextView.setText("Sub: ["+ o.getSubject()+"]");
                 }
         }
         return view;
 }

} }


For tablayout I recommend : http://developer.android.com/resources/tutorials/views/hello-tabwidget.html


you might want to read up on this Tab Layout | Android Development

it's a good starting point

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜