2017-09-02 2 views
0

ich setze auf klicken auf die Kartenansicht, wenn ich auf die Kartenansicht klicke das Fragment wird auf der Aktivität gezeigt ich nehme an, aber das Fragment wird nicht angezeigt der onclick von cardview funktioniert aber Fragment wird nicht angezeigt i versuche viel, aber keine Lösung Ich weiß nicht, warum das passiert. Es gibt keine Fehler auch, aber mein Fragment wird nicht einmal keinen Fehler gezeigt Voraus thanlks hier CodeFragment wird nicht angezeigt

Activity 
 

 
public class SubmitAddActivity extends AppCompatActivity implements CallbackFromFragment { 
 
    
 

 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.submitadd_layout); 
 
     
 
     findViewById(R.id.choose_category_layout).setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 
       Log.d("bullhead", "onClick: hellow rodl "); 
 
       fragmentTransaction=getSupportFragmentManager().beginTransaction(); 
 
       fragmentTransaction.replace(R.id.container,fragmentUsage); 
 
       fragmentTransaction.commit(); 
 
       fragmentUsage.setTYPE(1); 
 
      } 
 
     }); 
 
     
 
        submitbutton.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 

 
      } 
 
     }); 
 
     settingToolbar(); 
 

 
    } 
 

 
    
 

 

 

 
    @Override 
 
    public void setValues(int type, String value) { 
 
    if(type==1) 
 
    { 
 
     fragmentTransaction.remove(fragmentUsage); 
 
     category=value; 
 
    } 
 
    else if(type==2) 
 
    { 
 
     fragmentTransaction.remove(fragmentUsage); 
 
     location=value; 
 
    } 
 

 
    } 
 

 

 
}

Aktivität Layout

<ScrollView 
 
    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"> 
 
    <FrameLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content"> 
 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
     xmlns:tools="http://schemas.android.com/tools" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
 
     android:id="@+id/containerfragments" 
 
     android:fitsSystemWindows="true" 
 
     android:orientation="vertical" 
 
     tools:context="com.asad.taleembazar.activities.HomeActivity"> 
 

 
     
 
     <include 
 
      layout="@layout/cardview_choose_category_submitadds" 
 
      android:layout_height="wrap_content" 
 
      android:layout_width="match_parent" 
 
      /> 
 
     
 

 
    </LinearLayout> 
 
     <FrameLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:id="@+id/container" 
 

 
      /> 
 
    </FrameLayout> 
 

 
</ScrollView>

Fragment

public class SelectFragment extends Fragment implements com.asad.taleembazar.adpaters.callback { 
 
    private SelectCategorySubmitAddAdapter adapter; 
 
    private RecyclerView.LayoutManager layoutManager; 
 
    private ArrayList<String> arrayList=new ArrayList<>(); 
 
    CallbackFromFragment communication; 
 
    int type; 
 

 
    // TODO: Rename and change types of parameters 
 
    private String mParam1; 
 
    private String mParam2; 
 

 

 

 
    public SelectFragment() { 
 
     // Required empty public constructor 
 
    } 
 

 

 
    @Override 
 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
 
          Bundle savedInstanceState) { 
 
     View view = inflater.inflate(R.layout.activity_select_category_submit,container,false); 
 
     arrayList.add("Cars"); 
 
     arrayList.add("Mobiles"); 
 
     arrayList.add("Bags"); 
 
     RecyclerView recyclerViewforsubmitadd = (RecyclerView)view.findViewById(R.id.recyclerview_for_categoriessubmit); 
 
     layoutManager = new LinearLayoutManager(getActivity()); 
 
     recyclerViewforsubmitadd.setLayoutManager(layoutManager); 
 
     recyclerViewforsubmitadd.setHasFixedSize(true); 
 
     adapter = new SelectCategorySubmitAddAdapter(arrayList); 
 
     adapter.setOnClick(this); 
 
     recyclerViewforsubmitadd.setAdapter(adapter); 
 
     return view; 
 
    } 
 

 

 

 
    @Override 
 
    public void onAttach(Context context) { 
 
     super.onAttach(context); 
 
     communication = (CallbackFromFragment) context; 
 

 
    } 
 
    @Override 
 
    public void onClick(int adapterPosition) { 
 
     if(type==1) 
 
     communication.setValues(1,arrayList.get(adapterPosition)); 
 
     else if(type==2) 
 
      communication.setValues(1,arrayList.get(adapterPosition)); 
 

 
    } 
 
public void setTYPE(int i) 
 
{ 
 
    type=i; 
 
} 
 
}

+0

Sie sollten wirklich diesen Code reduzieren die minimale Arbeitsbeispiel zu schaffen, die das Problem demonstriert. Entfernen Sie alles andere –

+0

es ist jetzt reduziert –

Antwort

0

match_parent des Containers Framelayout nicht in Ihrem ScrollView arbeiten. Sie können entweder android:fillViewport="true" in Ihrem ScrollView oder Sie können eine feste Höhe für Ihren Container festlegen.

Try Code unten

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    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:fillViewport="true"> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/containerfragments" 
      android:fitsSystemWindows="true" 
      android:orientation="vertical" 
      tools:context="com.asad.taleembazar.activities.HomeActivity"> 


       <include 
        layout="@layout/cardview_choose_category_submitadds" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        /> 


     </LinearLayout> 
     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/container" 

      /> 
    </FrameLayout> 

</ScrollView> 
Verwandte Themen