• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Listview inside tabwidget

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/red"    android:layout_width="fill_parent" android:layout_height="wrap_content">
    <Button android:background="@drawable/homericon" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/button2"></Button>
        
        
</LinearLayout>
    
    
    
    
<TabHost 
    android:id="@android:id/tabhost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>
   </LinearLayout>

This is my layout xml for tabwidget and the code is
Code:
public class BookListTab extends TabActivity implements View.OnClickListener {

    
    
    Button homeButton;

    @Override
    public void onClick(View paramView) {
        if(paramView !=null){
        Intent intent = new Intent();
        intent.setClass(this, GridViewer.class);
        startActivity(intent);
        }
    }
    
    
    // This class is for list option in the main menu and it list all books read user with tabs
    // like books,authors,tag etc and it also has sort option 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        try{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.booklistview);
        
        homeButton = (Button) findViewById(R.id.button2);
        homeButton.setOnClickListener(this);
        
        
        TabHost tabHost = getTabHost();
        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("TEXT").setContent(new Intent(this, BookActivity.class)));
        
        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("LIST").setContent(new Intent(this, AuthorActivity.class)));
        tabHost.setCurrentTab(1); 

 

        

        }
        catch(Exception e){
            e.getLocalizedMessage();
        }
        }

Inside BookActivity class , i have code for listview with icons

Code:
public class BookActivity extends ListActivity {

String[] title = new String[] {
            "*New*Apple iPad Wi-Fi (16GB)",
            "7 Touch Tablet -2GB Google Android",

            "Apple iPad Wi-Fi (16GB) Rarely Used ",
            "Apple iPad Wi-Fi (16GB) AppleCase" };

    static final String[] detail = new String[] { "1h 37m Shipping: $10.00",
            "1h 39m Shipping: Free", "58m 6s Shipping: $10.00",
            "59m 30s Shipping: $10.95" };
    private Integer[] imgid = {
              R.drawable.boomerang,R.drawable.garden,R.drawable.index,
              R.drawable.kaku
            };
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bookactivity);
        
        
        

            setListAdapter(new MyCustomAdapter(this, R.layout.booklistrow,
                     title));
getListView().setTextFilterEnabled(true); 

    }
    public class MyCustomAdapter extends ArrayAdapter<String> {

        public MyCustomAdapter(Context context, int textViewResourceId,
        String[] objects) {
        super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
  
            View row=null;;
        try{
        LayoutInflater inflater=getLayoutInflater();
        row=inflater.inflate(R.layout.booklistrow, parent, false);
        TextView label=(TextView)row.findViewById(R.id.title);
        label.setText(title[position]);
        ImageView icon=(ImageView)row.findViewById(R.id.img);
        
        // if it is root folder we wont set icon or else we place approprate icons i.e file & folder
   

        }


    
        catch(Exception e){
            e.getLocalizedMessage();
        }
        return row;
        }
        
    
    
    
    }
}

and the layouts used for listview

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView android:text="book content"
              android:padding="15dip"
              android:textSize="18dip"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
     
    <TextView android:id="@+id/path" android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView android:id="@android:id/empty" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="No Data" />
</LinearLayout>

and this layout to inflate listview
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" 
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img" 
android:scaleType="centerCrop"
android:layout_width="70dp"
android:layout_height="70dp"/>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:id="@+id/title" 
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000000"
android:textSize="16sp" />


</LinearLayout>

</LinearLayout>

My problem is tabs are forming correctly but listview is not formed inside tabhost.

Any idea why list view is not showing,any clarification on the code ,you can ask

Thanks
 
Back
Top Bottom