Android Open Source - book Book List Fragment






From Project

Back to project page book.

License

The source code is released under:

MIT License

If you think the Android project book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fragments;
/*from  w  w w  .ja v a  2  s.  co m*/
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import book.Book;
import book.BookListAdapter;

import com.example.book.R;


public class BookListFragment extends Fragment implements OnItemClickListener, OnClickListener {
  
  private PagerActivity pager;
  private ListView bookList;
  private View view;
  private BookListAdapter bookAdapter;

                
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    if (container == null) {
            return null;
        }
    
    this.pager = (PagerActivity) getActivity();    
        this.view = (View)inflater.inflate(R.layout.booklist, container, false);
        
        
    this.bookList = (ListView)this.view.findViewById(R.id.bookList);    
    this.bookList.setOnItemClickListener(this);
    
    ImageButton btn = (ImageButton) this.view.findViewById(R.id.add);
    btn.setOnClickListener(this);
    this.refresh();
    
        return this.view;
    }
    
  public void refresh(){    
    if (this.pager != null){
      this.bookAdapter = new BookListAdapter(this.pager, this.pager.BOOKS);
      this.bookList.setAdapter(this.bookAdapter);
    }
  }
  
  @Override
  public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) {
    // TODO Auto-generated method stub
    Book book = (Book) item.getTag();
    this.pager.showBook( book );    
  }
  
  public void showAddDialog(){
    final PagerActivity pgr = this.pager;
    final EditText textBox = new EditText(this.pager);
    new AlertDialog.Builder(this.pager).setTitle("Create new book")    
    .setView(textBox)    
    .setPositiveButton("Create", new DialogInterface.OnClickListener() {    
      public void onClick(DialogInterface dialog, int whichButton) {            
        pgr.addNewBook(textBox.getText().toString());
        
    }}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton) {}}).show();            
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()){
      case R.id.add:
        this.showAddDialog();
      break;      
    }
    
    
    //this.pager.show(this.pager.CAMERA, true);    
  }
}




Java Source Code List

book.BookListAdapter.java
book.Book.java
book.ExpandableListAdapter.java
book.SelectableWordListAdapter.java
com.BookTable.java
com.Db.java
com.TranslationsTable.java
com.WordTable.java
fragments.BookListFragment.java
fragments.BookViewFragment.java
fragments.CameraFragment.java
fragments.EditBookFragment.java
fragments.PageAdapter.java
fragments.PagerActivity.java
translator.TranslateWordTask.java
translator.Translator.java