This is sure will a duplicate of This question.but I'm still unable to find the solution even crawling over the internet.I want to set the category
in the Cate_layout
by either using ArrayAdapter
or someCustomAdapter
(I have tried both, but no success :( )
This is the Logcat
FATAL EXCEPTION: main Process: tomestore.wixsite.com.tome, PID: 14405 android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.CardView Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.widget.CardView Caused by: java.lang.reflect.InvocationTargetException
I have a fragment BookFragment
public class BookFragment extends Fragment {
ListView listView;
String[] something ={"something", " nothing"};
public BookFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_book, container, false);
listView = view.findViewById(R.id.cateSlit);
listView.setAdapter(new ArrayAdapter<>(getActivity().getApplicationContext(),R.layout.cate_layout,R.id.catagory,something));
return view;
}
And this is cate_layout
<android.support.v7.widget.CardView
android:id="@+id/container_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:elevation="4dp"
android:focusable="true"
android:foreground="?attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/catagory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Category" />
.........
</android.support.v7.widget.CardView>
And Here is the fragment_book
<FrameLayout 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:orientation="vertical"
tools:context="tomestore.wixsite.com.tome.BookFragment">
<ListView
android:id="@+id/cateSlit"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "tomestore.wixsite.com.tome"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-storage:11.0.4'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-database:11.0.4'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
implementation 'com.android.support:recyclerview-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
// RecyclerView
compile 'com.android.support:recyclerview-v7:26.1.0'
// CardView
compile 'com.android.support:cardview-v7:26.1.0'
}
apply plugin: 'com.google.gms.google-services'