Question

I have an application about debts to user and user's debts. Main activity is TabActivity for switching two activities with custom lists.


It looks like (screenshot): http://i.stack.imgur.com/qts1f.png

The code is:

public class MainActivity extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        TextView tv = (TextView)findViewById(R.id.newDebtHeader);
        tv.setBackgroundResource(R.drawable.grad);
        tv.setTextColor(Color.BLACK);
        tv.setFadingEdgeLength(3);

        intent = new Intent().setClass(this, DebtsToMeList.class);

        spec = tabHost.newTabSpec("debts_to_me").setIndicator(null, res.getDrawable(R.drawable.ic_tab_debts_to_me)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MyDebtsList.class);

        spec = tabHost.newTabSpec("my_debts").setIndicator(null, res.getDrawable(R.drawable.ic_tab_my_debts)).setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);
    }
}

main.xml is:

<?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"
    android:padding="1dp">

    <TextView 
        android:id="@+id/newDebtHeader" 
        android:layout_height="24dip"
        android:layout_width="fill_parent"
        android:gravity="center_vertical|center_horizontal"
        android:textStyle="bold"
        android:textSize="16dip" 
        android:text="хДолги">
    </TextView> 
    <TabHost 
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp">
            <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"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
</LinearLayout>
enter code here

But I don't like TabActivity, I want change this two lists by horizontal finger drag. Could you please help me change my code?

Was it helpful?

Solution

If you look at this example, it uses the fling gesture with a view switcher and a little animation to get the effect I think that you are looking for... all that you would have to do is load your lists and then you should be able to swipe between them.

Hope this helps.

OTHER TIPS

It sounds to me like you want to utilize a Gallery, where the Gallery adapter creates your custom list views. Unfortunately this isn't as straightforward as it might seem. See Embedding ListView inside Gallery.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top