第一个问题:我按下按钮后我的标签不会滑动,我必须手动点击标签。在按下按钮之前滑动完美
第二个问题:我的标签上也没有显示我的列表。 adpater假设每次按下带输入的按钮时都会向列表视图吐出一个值,但列表没有显示
public class tablogger extends FragmentActivity {
ViewPager Tab;
TabPagerAdapter TabAdapter;
ActionBar actionBar;
ArrayAdapter<String> adapter;
ArrayList<String> list = new ArrayList<String>();
EditText benchStat;
EditText benchreps;
String benchfinals;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tablogger);
TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
Tab = (ViewPager)findViewById(R.id.pager);
Tab.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar = getActionBar();
actionBar.setSelectedNavigationItem(position); }
});
Tab.setAdapter(TabAdapter);
actionBar = getActionBar();
//Enable Tabs on Action Bar
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener(){
@Override
public void onTabReselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
Tab.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}};
//Add New Tab
actionBar.addTab(actionBar.newTab().setText("Bench").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("Squat").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("Dead").setTabListener(tabListener));
}
public void bencircle(View view) {
setContentView(R.layout.benchtab);
lv.setAdapter(adapter);
int benchmax = (int) ((100 * (Integer.parseInt(benchStat.getText().toString()))) /
(101.3 - (2.67123 * (Integer.parseInt(benchreps.getText().toString())))));
benchfinals = Integer.toString(benchmax);
String input = benchfinals;
if (input.length() > 0) {
// add string to the adapter, not the listview
Toast.makeText(this, benchfinals, Toast.LENGTH_SHORT).show();
adapter.add(input);
adapter.notifyDataSetChanged();
// no need to call adapter.notifyDataSetChanged(); as it is done by the adapter.add() method
}
}
public class TabPagerAdapter extends FragmentStatePagerAdapter {
public TabPagerAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
//Fragement for Android Tab
return new Bench();
case 1:
//Fragment for Ios Tab
return new Squat();
case 2:
//Fragment for Windows Tab
return new Dead();
}
return null;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 3; //No of Tabs
}
}
public class Bench extends Fragment /* implements View.OnClickListener*/ {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View android = inflater.inflate(R.layout.benchtab, container, false);
((TextView) android.findViewById(R.id.textView)).setText("");
adapter = new ArrayAdapter<String>(this.getActivity(), R.layout.simple_expandable_list_item_1, list);
lv = (ListView)android.findViewById(R.id.benchlist);
//android.findViewById(R.id.framecircle).setOnClickListener(this);
benchStat = (EditText)android.findViewById(R.id.benchstat_id);
benchreps = (EditText)android.findViewById(R.id.benchrepstat_id);
return android;
}
/*@Override
public void onClick(View v) {
setContentView(R.layout.benchtab);
lv.setAdapter(adapter);
int benchmax = (int) ((100 * (Integer.parseInt(benchStat.getText().toString()))) /
(101.3 - (2.67123 * (Integer.parseInt(benchreps.getText().toString())))));
benchfinals = Integer.toString(benchmax);
Toast.makeText(getActivity(), benchfinals, Toast.LENGTH_SHORT).show();
return;
}
*/
}
public class Squat extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View ios = inflater.inflate(R.layout.squattab, container, false);
((TextView)ios.findViewById(R.id.textView)).setText("squatter");
return ios;
}
}
public class Dead extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View windows = inflater.inflate(R.layout.deadtab, container, false);
((TextView)windows.findViewById(R.id.textView)).setText("deadenning");
return windows;
}
}
public void finish() {
// Prepare data intent
Intent data = new Intent();
data.putExtra("tabbenchkey", benchfinals);
//data.putExtra("tabsquatkey", squatfinal);
//data.putExtra("tabdeadkey", deadfinal);
//data.putExtra("tabpresskey", pressfinal);
//data.putExtra("tabpowerkey", powerfinal);
// Activity finished ok, return the data
setResult(RESULT_OK, data);
super.finish();
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bench_id"
android:layout_marginTop="42dp"
android:text="Weight"
android:layout_marginLeft="24dp"
android:textSize="18sp"
android:layout_marginBottom="40dp"
/>
<EditText
android:layout_width="60dp"
android:layout_height="wrap_content"
android:id="@+id/benchstat_id"
android:layout_marginTop="35dp"
android:layout_marginLeft="88dp"
android:inputType="number"
android:maxLength="3"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/benchrep_id"
android:layout_toRightOf="@+id/benchstat_id"
android:text="Reps"
android:textSize="18sp"
android:layout_marginTop="42dp"
android:layout_marginLeft="16dp"
/>
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="@+id/benchrepstat_id"
android:layout_toRightOf="@+id/benchrep_id"
android:layout_marginTop="35dp"
android:inputType="number"
android:maxLength="2"/>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="24dp"
android:layout_marginTop="22dp"
android:id="@+id/framecircle"
>
<at.markushi.ui.CircleButton
android:layout_width="72dip"
android:layout_height="72dip"
android:src="@drawable/ic_action_tick"
app:cb_color="#e51c23"
app:cb_pressed_ring_width="8dip"
android:onClick="bencircle"
android:id="@+id/circlebench"
/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/bench_id">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/benchlist">
</ListView>
</LinearLayout>
<EditText
android:id="@+id/txtItem"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="yolo"
/>
答案 0 :(得分:0)
您必须使用:
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
为每个标签提供片段,并使用片段布局提供按钮等。