フラグメント内にListView
を使用したい場合、上部にスワイプ可能なタブがあります。これらのタブはListView
で重複しており、タブ間でスワイプするとアプリがクラッシュします。リストビューのオーバーラップTabLayoutとボタンをフラグメント内で使用すると
これは、それがどのように見えるかです:私は解決策を検索するためのすべての日をしようとしてきたが、私のために働いていたものを発見していない
...それは私の最初の質問ですので、ここでは、私が望むものとできるだけ理解できるようにしようとしています(そして、何か他のものが必要な場合は、Git hereにあります)。
私は膨らませる必要があるフラグメントのためCoordinatorLayout
を使用しますが、私はListView
とそのレイアウトは一緒にうまくいかなかったので、今、私はちょうどそれがRelativeLayout
またはLinearLayout
で動作するように取得したいことをお読みください。私もRecyclerView
を使ってみましたが、うまくいきませんでした。
LinearLayout
とRelativeLayout
の間で変更を試みました。だから私は誰かが私を助けることができるかどうか聞いてみたかった。以下は、コードの現在の見方です。
activity_main.xml -whereタブとviewpagerは、自分の意見 -where listlayoutが
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_weight="1.0">
</ListView>
</RelativeLayout>
FRAに設定されている
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
workout_list_layout.xmlを有しますgment_workout.xml タブの下のリストに
<RelativeLayout
android:id="@+id/main_list"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_below="@id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/workoutList">
<include layout="@layout/workout_list_layout"
android:id="@+id/list"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_above="@id/workoutList"
/>
<Button
android:id="@+id/button_start_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|left"
android:text="Start"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_above="@id/workoutList"/>
</RelativeLayout>
を示すべき-aフラグメントPageFragment.javaが は、すべてのフラグメント
public class PageFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
public static PageFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
PageFragment fragment = new PageFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view;
if(mPage == 1){
view = inflater.inflate(R.layout.fragment_workout, container, false);
WorkoutListFragment workoutListFragment = (WorkoutListFragment)getFragmentManager().findFragmentByTag("workoutlistfragment");
if (workoutListFragment == null){
workoutListFragment = new WorkoutListFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(android.R.id.content, workoutListFragment,"workoutlistfragment");
transaction.commit();
}
Button button = (Button) view.findViewById(R.id.button_start_workout);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button_start_workout:
Intent intent = new Intent(view.getContext(), TimerWindow.class);
startActivity(intent);
break;
}
}
});
}else if(mPage == 2){
view = inflater.inflate(R.layout.fragment_performance, container, false);
}else{
view = inflater.inflate(R.layout.fragment_options, container, false);
}
return view;
}
}
WorkoutListFragment.java を-handles - ビューを膨らませるリストフラグメント
public class WorkoutListFragment extends ListFragment {
ArrayList<String> listItems = new ArrayList<String>(); //List items
ArrayAdapter<String> adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.workout_list_layout, container, false);
return rootView;
}
public void onListItemClick(ListView listView, View view, int position, long id){
ViewGroup viewGroup = (ViewGroup) view;
TextView textView = (TextView) viewGroup.findViewById(R.id.textItem);
Toast.makeText(getActivity(), textView.getText().toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" , "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
//METHOD WHICH WILL HANDLE DYNAMIC INSERTION
public void addItems(String workoutTitle, View v) {
listItems.add(workoutTitle);
adapter.notifyDataSetChanged();
}
}
ありがとうございます!それを試み、それが動作しませんでした...ここで は、それが今どのように見えるかです: https://drive.google.com/open?id=0B5J-MYgiEYRwNHVSR1VhY2hKR1k 他のアイデア? –