在Tabhost中的Android刷卡
问题描述:
我如何实现在tabhost中的tab之间刷卡谢谢,以下是我的xml文件和java文件。在Tabhost中的Android刷卡
请帮助我在此tabhost中实施刷卡,有人了解更多关于tabhost的信息,请分享所有tabhost选项。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bRecharge">
</FrameLayout>
</TabHost>
的java文件
package com.veristics.tijo.smartrecharge;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.view.Menu;
import android.widget.TextView;
import com.veristics.san.smartrecharge.net.AsyncNetCall;
import java.util.HashMap;
public class MainActivity extends TabActivity{
float lastX;
AsyncNetCall asyncNetCall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
TabHost.TabSpec mobile = tabHost.newTabSpec("Mobile");
mobile.setIndicator("mobile");
Intent mob = new Intent(MainActivity.this, MobileActivity.class);
mobile.setContent(mob);
TabHost.TabSpec dth = tabHost.newTabSpec("DTH");
dth.setIndicator("DTH");
Intent d = new Intent(MainActivity.this, DTHActivity.class);
dth.setContent(d);
TabHost.TabSpec datacard = tabHost.newTabSpec("Datacard");
datacard.setIndicator("datacard");
Intent dc = new Intent(MainActivity.this, DataCardActivity.class);
datacard.setContent(dc);
tabHost.addTab(mobile);
tabHost.addTab(dth);
tabHost.addTab(datacard);
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.activity_custom_actionbar, null);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
new AsyncNetCall(this).execute("getUserBalance");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_account_log:
Intent account_log = new Intent(this,AccountLogActivity.class);
startActivity(account_log);
return true;
case R.id.action_recharge_log:
Intent recharge = new Intent(this,RechargeLogActivity.class);
startActivity(recharge);
return true;
case R.id.action_logout:
Intent login = new Intent(this, LoginActivity.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
答
@Tijo约翰:
不错的办法
- 使用弃用代码TabActivity。
该类在API层面弃用13.新的应用程序应该使用 片段,而不是此类;继续在旧设备上运行, 可以使用V4支持库,它提供了一个版本的 片段API的
最佳途径
ViewPager通常与Fragment结合使用,它是一个 提供和管理每个页面生命周期的便捷方式。 是标准适配器,用于使用ViewPager的片段,其中涵盖了最常见的用例。
请看看这个问题,http://*.com/questions/23843479/android-tabs-without-actionbar不建议使用标签主机 –
刷卡。使用视图寻呼机适配器。 http://codetheory.in/android-swipe-views-with-tabs/ –
谢谢@Madhukar Hebbar你,但我需要在tabhost实施刷卡。 –